본문 바로가기

Python

[QT] 구구단 출력하기

myqt04.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>580</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>80</x>
      <y>40</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>단수 :</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="le">
    <property name="geometry">
     <rect>
      <x>120</x>
      <y>40</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="pb">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>70</y>
      <width>151</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>출력하기</string>
    </property>
   </widget>
   <widget class="QTextEdit" name="te">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>110</y>
      <width>151</width>
      <height>291</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>

 

myqt04.py

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.btnClick)
        
    def btnClick(self):
        dan = self.le.text()
        ddan = int(dan)
        txt = "*****"+dan+"단*****\n"
        for i in range(1,9+1):
            txt += dan + " * " + str(i) + " = " + str(ddan*i) + "\n"
        
        self.te.setText(txt)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = WindowClass()
    myWindow.show()
    app.exec_()

실행화면

 

'Python' 카테고리의 다른 글

[QT] 가위바위보 게임  (0) 2023.06.29
[QT] 전화기 만들기  (0) 2023.06.28
[QT] 로또 만들기  (0) 2023.06.28
[QT] 버튼 클릭 시 감소  (0) 2023.06.28
[Python] 홀 짝 게임  (0) 2023.06.28