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>
'Python > Python 기초' 카테고리의 다른 글
파이썬(QT) 가위바위보 프로그램 만들기 예제 (0) | 2023.06.29 |
---|---|
파이썬(QT) 전화번호 팝업창 띄우기 예제 (0) | 2023.06.28 |
파이썬(QT) 로또 출력 예제 (0) | 2023.06.28 |
파이썬 야구게임 예제 (0) | 2023.06.27 |
안드로이드 돌핀버전으로 자바와 비슷한 GUI해보기(설정) (0) | 2023.06.26 |