Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags more
Archives
Today
Total
관리 메뉴

기록

pyqt 파이썬 구구단 본문

카테고리 없음

pyqt 파이썬 구구단

9400 2023. 1. 2. 19:42

화면단

import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic

form_class = uic.loadUiType("main03.ui")[0]


class WindowClass(QMainWindow, form_class) :
    def __init__(self) :
        super().__init__()
        self.setupUi(self)
        
        self.pb.clicked.connect(self.myclick)
        
    def myclick(self):
        num = self.le.text()
        dan = int(num)
        # code ="";
        # code+="{}*{}={} \n".format(dan,1,dan*1)
        # code+="{}*{}={} \n".format(dan,2,dan*2)
        # code+="{}*{}={} \n".format(dan,3,dan*3)
        # code+="{}*{}={} \n".format(dan,4,dan*4)
        # code+="{}*{}={} \n".format(dan,5,dan*5)
        # code+="{}*{}={} \n".format(dan,6,dan*6)
        # code+="{}*{}={} \n".format(dan,7,dan*7)
        # code+="{}*{}={} \n".format(dan,8,dan*8)
        # code+="{}*{}={} \n".format(dan,9,dan*9)
        # self.te.setText(code)
        
        txt="";
        for i in range(1,9+1):
            # txt+= str(dan) +"+" +str(i)+"="+str(dan*i)+"\n" 
            txt+="{} * {} = {} \n".format(dan,i,i*dan)
        
        self.te.setText(txt)

if __name__ == "__main__" :
    #QApplication : 프로그램을 실행시켜주는 클래스
    app = QApplication(sys.argv) 
    #WindowClass의 인스턴스 생성
    myWindow = WindowClass() 
    #프로그램 화면을 보여주는 코드
    myWindow.show()
    #프로그램을 이벤트루프로 진입시키는(프로그램을 작동시키는) 코드
    app.exec_()

출력 완료!

Comments