728x90
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.myclick)
def myclick(self):
arr = list(range(1,45+1))
for i in range(100) :
ran = int(random()*45)
a = arr[0]
arr[0] = arr[ran]
arr[ran]=a
print(arr)
arr2 = arr[0:6]
arr2.sort()
# arr2 = sorted(arr[0:6])
print(arr2)
self.lbl1.setText(str(arr2[0]))
self.lbl2.setText(str(arr2[1]))
self.lbl3.setText(str(arr2[2]))
self.lbl4.setText(str(arr2[3]))
self.lbl5.setText(str(arr2[4]))
self.lbl6.setText(str(arr2[5]))
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="lbl1">
<property name="geometry">
<rect>
<x>81</x>
<y>151</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl2">
<property name="geometry">
<rect>
<x>137</x>
<y>151</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl3">
<property name="geometry">
<rect>
<x>193</x>
<y>151</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl4">
<property name="geometry">
<rect>
<x>248</x>
<y>151</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl5">
<property name="geometry">
<rect>
<x>304</x>
<y>151</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QLabel" name="lbl6">
<property name="geometry">
<rect>
<x>360</x>
<y>151</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>__</string>
</property>
</widget>
<widget class="QPushButton" name="pb">
<property name="geometry">
<rect>
<x>80</x>
<y>210</y>
<width>341</width>
<height>51</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>
'Python > Python 기초' 카테고리의 다른 글
파이썬(QT) 전화번호 팝업창 띄우기 예제 (0) | 2023.06.28 |
---|---|
파이썬(QT) 구구단 입력 받아 출력 예제 (0) | 2023.06.28 |
파이썬 야구게임 예제 (0) | 2023.06.27 |
안드로이드 돌핀버전으로 자바와 비슷한 GUI해보기(설정) (0) | 2023.06.26 |
안드로이드 돌핀버전 설치 (0) | 2023.06.26 |