728x90
import sys
from PyQt5 import(uic)
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random
form_class = uic.loadUiType("myqt06.ui")[0]
class WindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pb.clicked.connect(self.myclick)
def myclick(self):
me = self.pte_mine.toPlainText()
arr = ["가위","바위","보"]
ran = int(random()*3)
com = arr[ran]
print(com)
self.pte_com.setPlainText(com);
if me==com:
self.pte_result.setPlainText("비겼습니다.");
elif (me=="가위" and com=="보")or (me=="바위" and com=="가위")or (me=="보" and com=="바위") :
self.pte_result.setPlainText("이겼습니다!.")
else:
self.pte_result.setPlainText("졌습니다.!.")
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="lbl_mine">
<property name="geometry">
<rect>
<x>60</x>
<y>100</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>나</string>
</property>
</widget>
<widget class="QLabel" name="lbl_com">
<property name="geometry">
<rect>
<x>60</x>
<y>160</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>com</string>
</property>
</widget>
<widget class="QLabel" name="lbl_result">
<property name="geometry">
<rect>
<x>60</x>
<y>230</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>결과</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="pte_mine">
<property name="geometry">
<rect>
<x>160</x>
<y>100</y>
<width>111</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPlainTextEdit" name="pte_com">
<property name="geometry">
<rect>
<x>160</x>
<y>160</y>
<width>111</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPlainTextEdit" name="pte_result">
<property name="geometry">
<rect>
<x>160</x>
<y>230</y>
<width>111</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pb">
<property name="geometry">
<rect>
<x>50</x>
<y>290</y>
<width>231</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.29 |
---|---|
파이썬(QT) 별찍기 예제 (0) | 2023.06.29 |
파이썬(QT) 전화번호 팝업창 띄우기 예제 (0) | 2023.06.28 |
파이썬(QT) 구구단 입력 받아 출력 예제 (0) | 2023.06.28 |
파이썬(QT) 로또 출력 예제 (0) | 2023.06.28 |