myqt03.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="lbl1">
<property name="geometry">
<rect>
<x>160</x>
<y>90</y>
<width>56</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl2">
<property name="geometry">
<rect>
<x>240</x>
<y>90</y>
<width>56</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl3">
<property name="geometry">
<rect>
<x>310</x>
<y>90</y>
<width>56</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl4">
<property name="geometry">
<rect>
<x>380</x>
<y>90</y>
<width>56</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl5">
<property name="geometry">
<rect>
<x>450</x>
<y>90</y>
<width>56</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl6">
<property name="geometry">
<rect>
<x>530</x>
<y>90</y>
<width>56</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QPushButton" name="pb">
<property name="geometry">
<rect>
<x>220</x>
<y>160</y>
<width>251</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>로또생성하기</string>
</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>
myqt03.py
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random
form_class = uic.loadUiType("myqt03.ui")[0]
class WindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pb.clicked.connect(self.btnClick)
def btnClick(self):
lotto = [i+1 for i in range(45)]
for i in range(100):
rnd = int(random()*45)
temp = lotto[0]
lotto[0] = lotto[rnd]
lotto[rnd] = temp
lottolist = sorted(lotto[:6])
self.lbl1.setText(str(lottolist[0]))
self.lbl2.setText(str(lottolist[1]))
self.lbl3.setText(str(lottolist[2]))
self.lbl4.setText(str(lottolist[3]))
self.lbl5.setText(str(lottolist[4]))
self.lbl6.setText(str(lottolist[5]))
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = WindowClass()
myWindow.show()
app.exec_()
실행 화면

'Python' 카테고리의 다른 글
| [QT] 전화기 만들기 (0) | 2023.06.28 |
|---|---|
| [QT] 구구단 출력하기 (0) | 2023.06.28 |
| [QT] 버튼 클릭 시 감소 (0) | 2023.06.28 |
| [Python] 홀 짝 게임 (0) | 2023.06.28 |
| [Python] 가위 바위 보 게임 (0) | 2023.06.28 |