'''
from tkinter import *
from tkinter.messagebox import *
import random
root = Tk()
label = Label(root, text='Rock Paper scissors')
label.pack()
b1 = Button(root, text='rock')
b1.pack()
b2 = Button(root, text='paper')
b2.pack()
b3 = Button(root, text='scissors')
b3.pack()
def btn1_click(event):
if askyesno("확인","Are you sure?"):
print("you played rock.")
np=random.randint(0,2)
up=0
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("rock >>", end=" ")
if np==up:
print("Tie")
elif np==1:
print("Computer win")
else:
print("User win")
else:
pass
def btn2_click(event):
if askyesno("확인","Are you sure?"):
print("you played paper.")
np=random.randint(0,2)
up=1
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("paper >>", end=" ")
if np==up:
print("Tie")
elif np==2:
print("Computer win")
else:
print("User win")
else:
pass
def btn3_click(event):
if askyesno("확인","Are you sure?"):
print("you played scissors.")
np=random.randint(0,2)
up=2
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("scissors >>", end=" ")
if np==up:
print("Tie")
print("Computer win")
else:
print("User win")
else:
pass
b1.bind('<Button-1>', btn1_click)
b2.bind('<Button-1>', btn2_click)
b3.bind('<Button-1>', btn3_click)
root.mainloop()
# listbox = Listbox(root, exportselection=False)
# label = Label(root, text='제목')
# entry = Entry(root)
# text = Text(root)
# b1 = Button(root, text='생성')
# b2 = Button(root, text='수정')
# b3 = Button(root, text='삭제')
# listbox.grid(row=0, column=0, columnspan=3, sticky='ew')
# label.grid(row=1, column=0)
# entry.grid(row=1, column=1, columnspan=2, sticky='ew')
# text.grid(row=2, column=0, columnspan=3)
# b1.grid(row=3, column=0, sticky='ew')
# b2.grid(row=3, column=1, sticky='ew')
# b3.grid(row=3, column=2, sticky='ew')
# root.mainloop()
'''
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# self.setWindowTitle('一个无标题的应用程序')
# self.move(300, 300)
# self.resize(400, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget
# from PyQt5.QtGui import QIcon
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# self.setWindowTitle('Icon')
# self.setWindowIcon(QIcon('pythonlogo.png'))
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# close window
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
# from PyQt5.QtCore import QCoreApplication
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# btn = QPushButton('click me to make the tab commit 自杀', self)
# btn.setToolTip('If you click this, the tab will commit 自杀(means su!c!de)')
# btn.move(10, 50)
# btn.resize(btn.sizeHint())
# btn.clicked.connect(QCoreApplication.instance().quit)
#
# self.setWindowTitle('The 自杀 tab')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# #tooltip
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QToolTip
# from PyQt5.QtGui import QFont
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# QToolTip.setFont(QFont('SansSerif', 10))
# self.setToolTip('This is a <b>QWidget</b> widget')
#
# btn = QPushButton('Button', self)
# btn.setToolTip('This is a <b>QPushButton</b> widget')
# btn.move(50, 50)
# btn.resize(btn.sizeHint())
#
# self.setWindowTitle('Tooltips')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
#status bar
# import sys
# from PyQt5.QtWidgets import QApplication, QMainWindow
#
#
# class MyApp(QMainWindow):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# self.statusBar().showMessage('there is nothing to do. please exit.')
#
# self.setWindowTitle('Statusbar')
# self.setGeometry(300, 300, 300, 200)
# self.show()
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp
# from PyQt5.QtGui import QIcon
#
#
# class MyApp(QMainWindow):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# exitAction = QAction(QIcon('exit.png'), 'Start thing', self)
# exitAction.setShortcut('Alt+F4')
# exitAction.setStatusTip('Press it')
# exitAction.triggered.connect(qApp.quit)
#
# self.statusBar()
#
# menubar = self.menuBar()
# menubar.setNativeMenuBar(False)
# filemenu = menubar.addMenu('&File')
# filemenu.addAction(exitAction)
#
# self.setWindowTitle('Menubar')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp
# from PyQt5.QtGui import QIcon
#
#
# class MyApp(QMainWindow):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# exitAction = QAction('Random button', self)
# exitAction.setShortcut('Alt+F4')
# exitAction.setStatusTip('click it')
# exitAction.triggered.connect(qApp.quit)
#
# self.statusBar()
# self.toolbar = self.addToolBar('Exit')
# self.toolbar.addAction(exitAction)
#
# self.setWindowTitle('Toolbar')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# self.setWindowTitle('A useless tab that only appears in the center')
# self.resize(500, 350)
# self.center()
# self.show()
#
# def center(self):
# qr = self.frameGeometry()
# cp = QDesktopWidget().availableGeometry().center()
# qr.moveCenter(cp)
# self.move(qr.topLeft())
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# from PyQt5.QtCore import QTime, Qt
# time = QTime.currentTime()
# print(time.toString('a h.m.s'))
# print(time.toString('a hh.mm.ss'))
# print(time.toString(Qt.DefaultLocaleLongDate))
# print(time.toString(Qt.DefaultLocaleShortDate))
# #date
# from PyQt5.QtCore import QDateTime, Qt
#
# datetime = QDateTime.currentDateTime()
# print(datetime.toString('d.M.yy hh:mm:ss'))
# print(datetime.toString('dd.MM.yyyy, hh:mm:ss'))
# print(datetime.toString(Qt.DefaultLocaleLongDate))
# print(datetime.toString(Qt.DefaultLocaleShortDate))
#date in gui
# import sys
# from PyQt5.QtWidgets import QApplication, QMainWindow
# from PyQt5.QtCore import QDate, Qt
#
#
# class MyApp(QMainWindow):
#
# def __init__(self):
# super().__init__()
# self.date = QDate.currentDate()
# self.initUI()
#
# def initUI(self):
# self.statusBar().showMessage(self.date.toString(Qt.DefaultLocaleLongDate))
#
# self.setWindowTitle('Date')
# self.setGeometry(300, 300, 400, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
#
# lbl_red = QLabel('Red')
# lbl_green = QLabel('Green')
# lbl_blue = QLabel('Blue')
#
# lbl_red.setStyleSheet("color: red;"
# "border-style: solid;"
# "border-width: 2px;"
# "border-color: #FA8072;"
# "border-radius: 3px")
# lbl_green.setStyleSheet("color: green;"
# "background-color: #7FFFD4")
# lbl_blue.setStyleSheet("color: blue;"
# "background-color: #87CEFA;"
# "border-style: dashed;"
# "border-width: 3px;"
# "border-color: #1E90FF")
#
# vbox = QVBoxLayout()
# vbox.addWidget(lbl_red)
# vbox.addWidget(lbl_green)
# vbox.addWidget(lbl_blue)
#
# self.setLayout(vbox)
#
# self.setWindowTitle('Stylesheet')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# label1 = QLabel('press this->', self)
# label1.move(20, 20)
# label2 = QLabel('dont press this->', self)
# label2.move(20, 60)
#
# btn1 = QPushButton('Button', self)
# btn1.move(100, 15)
# btn2 = QPushButton('Button', self)
# btn2.move(150, 53)
#
# self.setWindowTitle('Absolute Positioning')
# self.setGeometry(300, 300, 400, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QVBoxLayout
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# okButton = QPushButton('OK')
# cancelButton = QPushButton('Cancel')
#
# hbox = QHBoxLayout()
# hbox.addStretch(1)
# hbox.addWidget(okButton)
# hbox.addWidget(cancelButton)
# hbox.addStretch(1)
#
# vbox = QVBoxLayout()
# vbox.addStretch(3)
# vbox.addLayout(hbox)
# vbox.addStretch(1)
#
# self.setLayout(vbox)
#
# self.setWindowTitle('Box Layout')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QTextEdit)
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# grid = QGridLayout()
# self.setLayout(grid)
#
# grid.addWidget(QLabel('Title:'), 0, 0)
# grid.addWidget(QLabel('Author:'), 1, 0)
# grid.addWidget(QLabel('Review:'), 2, 0)
#
# grid.addWidget(QLineEdit(), 0, 1)
# grid.addWidget(QLineEdit(), 1, 1)
# grid.addWidget(QTextEdit(), 2, 1)
#
# self.setWindowTitle('QGridLayout')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
#3 buttons
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# btn1 = QPushButton('&press this', self)
# btn1.setCheckable(True)
# btn1.toggle()
#
# btn2 = QPushButton(self)
# btn2.setText('You can press this but I dont recommend doing it')
#
# btn3 = QPushButton('dont press this', self)
# btn3.setEnabled(False)
#
# vbox = QVBoxLayout()
# vbox.addWidget(btn1)
# vbox.addWidget(btn2)
# vbox.addWidget(btn3)
#
# self.setLayout(vbox)
# self.setWindowTitle('QPushButton')
# self.setGeometry(300, 300, 300, 200)
# self.show()
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# qlabel
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
# from PyQt5.QtCore import Qt
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# label1 = QLabel('First Label', self)
# label1.setAlignment(Qt.AlignCenter)
#
# label2 = QLabel('Second Label', self)
# label2.setAlignment(Qt.AlignVCenter)
#
# font1 = label1.font()
# font1.setPointSize(20)
#
# font2 = label2.font()
# font2.setFamily('Times New Roman')
# font2.setBold(True)
#
# label1.setFont(font1)
# label2.setFont(font2)
#
# layout = QVBoxLayout()
# layout.addWidget(label1)
# layout.addWidget(label2)
#
# self.setLayout(layout)
#
# self.setWindowTitle('QLabel')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QCheckBox
# from PyQt5.QtCore import Qt
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# cb = QCheckBox('Show title', self)
# cb.move(20, 20)
# cb.toggle()
# cb.stateChanged.connect(self.changeTitle)
#
# self.setWindowTitle('QCheckBox')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
# def changeTitle(self, state):
# if state == Qt.Checked:
# self.setWindowTitle('QCheckBox')
# else:
# self.setWindowTitle(' ')
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QRadioButton
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# rbtn1 = QRadioButton('on', self)
# rbtn1.move(50, 50)
# rbtn1.setChecked(True)
#
# rbtn2 = QRadioButton(self)
# rbtn2.move(50, 70)
# rbtn2.setText('off')
#
# self.setGeometry(300, 300, 300, 200)
# self.setWindowTitle('QRadioButton')
# self.show()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# a savage menu
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# btn1 = QPushButton('play(press alt+F4 to unlock)', self)
# btn1.setEnabled(False)
# vbox = QVBoxLayout()
# vbox.addWidget(btn1)
# self.setLayout(vbox)
# self.setWindowTitle('A fun game')
# self.setGeometry(300, 300, 300, 200)
# self.show()
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox
#
#
# class MyApp(QWidget):
#
# def __init__(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# self.lbl = QLabel('Option1', self)
# self.lbl.move(50, 150)
#
# cb = QComboBox(self)
# cb.addItem('Option1')
# cb.addItem('Option2')
# cb.addItem('Option3')
# cb.addItem('Option4')
# cb.move(50, 50)
#
# cb.activated[str].connect(self.onActivated)
#
# self.setWindowTitle('QComboBox')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
# def onActivated(self, text):
# self.lbl.setText(text)
# self.lbl.adjustSize()
#
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# combo box
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.lbl = QLabel('Option1', self)
self.lbl.move(50, 150)
cb = QComboBox(self)
cb.addItem('Option1')
cb.addItem('Option2')
cb.addItem('Option3')
cb.addItem('Option4')
cb.move(50, 50)
cb.activated[str].connect(self.onActivated)
self.setWindowTitle('QComboBox')
self.setGeometry(300, 300, 300, 200)
self.show()
def onActivated(self, text):
self.lbl.setText(text)
self.lbl.adjustSize()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())