import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
from PyQt5.Qt import QLabel
from PyQt5.uic.Compiler.qtproxies import QtWidgets, QtCore
import random
from _operator import eq
form_class = uic.loadUiType("main04.ui")[0]
class MyWindow(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pb.clicked.connect(self.myclick)
def myclick(self):
mine =""
com =""
result=""
# print("hello")
mine = self.leMine.text()
print(mine)
rnd = random.random();
if rnd>0.5:
com = "홀"
else:
com = "짝"
if mine == "홀" or mine =="짝":
if com != mine :
result = "짐"
else :
result = "이김"
elif mine != "홀" and mine !="짝" :
result = "다시 입력"
print("나:",mine)
print("컴:",com)
print("결과:",result)
self.leCom.setText(com)
self.leResult.setText(result)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = MyWindow()
myWindow.show()
app.exec_()
main04.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>762</width>
<height>596</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="lbl2">
<property name="geometry">
<rect>
<x>180</x>
<y>120</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>컴:</string>
</property>
</widget>
<widget class="QPushButton" name="pb">
<property name="geometry">
<rect>
<x>180</x>
<y>210</y>
<width>191</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>게임하기</string>
</property>
</widget>
<widget class="QLabel" name="lbl3">
<property name="geometry">
<rect>
<x>180</x>
<y>170</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>결과:</string>
</property>
</widget>
<widget class="QLabel" name="lbl1">
<property name="geometry">
<rect>
<x>180</x>
<y>80</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>나:</string>
</property>
</widget>
<widget class="QLineEdit" name="leMine">
<property name="geometry">
<rect>
<x>230</x>
<y>90</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="leCom">
<property name="geometry">
<rect>
<x>230</x>
<y>130</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="leResult">
<property name="geometry">
<rect>
<x>230</x>
<y>180</y>
<width>113</width>
<height>21</height>
</rect>
</property>
<property name="inputMask">
<string/>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
'공부 기록노트 > python' 카테고리의 다른 글
[python]day3. 파이큐티(PyQt5 ) - 가위바위보 게임 만들기 (0) | 2023.01.03 |
---|---|
[python]day3. 파이큐티(PyQt5 ) - 로또번호 번호 출력하기 (0) | 2023.01.03 |
[python]day3. 파이큐티(PyQt5 ) - 구구단 출력 (0) | 2023.01.03 |
[python]day3. 파이큐티(PyQt5 ) - 숫자 증가시키기 (0) | 2023.01.03 |
[python]day3. 파이큐티(PyQt5 ) 시작하기 - designer실행 (1) | 2023.01.03 |