Python/Python 기초
파이썬(QT) 구구단 입력 받아 출력 예제
미눅스[멘토]
2023. 6. 28. 20:59
728x90
import sys
from PyQt5 import(uic)
from PyQt5.QtWidgets import QApplication, QMainWindow
form_class = uic.loadUiType("myqt04.ui")[0]
class WindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pb.clicked.connect(self.myclick)
def myclick(self):
a=int(self.le.text())
b="";
for i in range(1,9+1):
b += str(a) + "*" + str(i) + "=" + str(a*i)+"\n"
self.te.setText(b)
if __name__ == '__main__':
app = QApplication(sys.argv)
myWindow = WindowClass()
myWindow.show()
app.exec_()
UI코드
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>mainWindow</class>
<widget class="QMainWindow" name="mainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="lbl_dan">
<property name="geometry">
<rect>
<x>90</x>
<y>40</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>단수</string>
</property>
</widget>
<widget class="QLineEdit" name="le">
<property name="geometry">
<rect>
<x>130</x>
<y>40</y>
<width>231</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pb">
<property name="geometry">
<rect>
<x>80</x>
<y>90</y>
<width>281</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>출력하기</string>
</property>
</widget>
<widget class="QTextEdit" name="te">
<property name="geometry">
<rect>
<x>80</x>
<y>150</y>
<width>281</width>
<height>391</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>