Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 로또만들기 본문

PYTHON

PYQT 로또만들기

9400 2023. 1. 2. 19:48

<?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>748</width>
    <height>602</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>40</x>
      <y>40</y>
      <width>41</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>__</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>130</y>
      <width>161</width>
      <height>51</height>
     </rect>
    </property>
    <property name="text">
     <string>click</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl2">
    <property name="geometry">
     <rect>
      <x>90</x>
      <y>40</y>
      <width>41</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>__</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl3">
    <property name="geometry">
     <rect>
      <x>130</x>
      <y>40</y>
      <width>41</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>__</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl5">
    <property name="geometry">
     <rect>
      <x>220</x>
      <y>40</y>
      <width>41</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>__</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl6">
    <property name="geometry">
     <rect>
      <x>260</x>
      <y>40</y>
      <width>41</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>__</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl4">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>40</y>
      <width>31</width>
      <height>31</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>748</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

 

코드

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

form_class = uic.loadUiType("main05.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 = [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,32,33,34,35,36,37,38,39,40,
            41,42,43,44,45]
        
        for i in range(1000):
            rnd = random.random()*len(arr)
            rnd2 = int(rnd)
            print(rnd2)
            a = arr[rnd2]
            b = arr[0]
            arr[0]=a
            arr[rnd2]=b
        
        self.lbl1.setText(str(arr[0]))
        self.lbl2.setText(str(arr[1]))
        self.lbl3.setText(str(arr[2]))
        self.lbl4.setText(str(arr[3]))
        self.lbl5.setText(str(arr[4]))
        self.lbl6.setText(str(arr[5]))
        
if __name__ == "__main__" :
    #QApplication : 프로그램을 실행시켜주는 클래스
    app = QApplication(sys.argv) 
    #WindowClass의 인스턴스 생성
    myWindow = WindowClass() 
    #프로그램 화면을 보여주는 코드
    myWindow.show()
    #프로그램을 이벤트루프로 진입시키는(프로그램을 작동시키는) 코드
    app.exec_()

출력 성공

Comments