如何使用 pyqt5 将 python 代码转换为图形用户界面? (禁止使用qt designer或其他应用程序,我必须自己编写代码)
how to transform a python code to a gui using pyqt5? (using qt designer or other app are prohibited, i have to code it my self)
我在 python 中写了一个简单的代码,我想为它制作一个图形用户界面,我想使用 pyqt5。
如何使用 pyqt5 将我的代码制作成图形用户界面?
不知道如何以及从哪里开始......
有什么好的资源可以免费从头开始学习pyqt5吗?
顺便说一句,这是我的代码:
随机导入
定义重启():
return猜谜游戏()
def 猜谜游戏():
数字= random.sample(范围(9),5)
print("instruction:")
print("Correct = C, Wrong= W, Missplaced = M")
print("there are no repeative digits.")
lst=[0,0,0,0,0,0,0,0,0]
while (lst[0] != numbers[0] or lst[1] != numbers[1] or lst[2] != numbers[2] or lst[3] != numbers[3] or lst[4] != numbers[4]):
g = int(input("Guess the five digit number:"))
lst = [int(y) for y in str(g)]
showcase = str()
if (lst[0] == numbers[1] or lst[0] == numbers[2] or lst[0] == numbers[3] or lst[0] == numbers[4]):
showcase= showcase + str("M,")
elif (lst[0] != numbers[0] and lst[0] != numbers[1] and lst[0] != numbers[2] and lst[0] != numbers[3] and lst[0] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
if (lst[1] == numbers[0] or lst[1] == numbers[2] or lst[1] == numbers[3] or lst[1] == numbers[4]):
showcase = showcase + str("M,")
elif (lst[1] != numbers[0] and lst[1] != numbers[1] and lst[1] != numbers[2] and lst[1] != numbers[3] and lst[1] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
if (lst[2] == numbers[0] or lst[2] == numbers[1] or lst[2] == numbers[3] or lst[2] == numbers[4]):
showcase = showcase + str("M,")
elif (lst[2] != numbers[0] and lst[2] != numbers[1] and lst[2] != numbers[2] and lst[2] != numbers[3] and lst[2] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
if (lst[3] == numbers[0] or lst[3] == numbers[1] or lst[3] == numbers[2] or lst[3] == numbers[4]):
showcase = showcase + str("M,")
elif (lst[3] != numbers[0] and lst[3] != numbers[1] and lst[3] != numbers[2] and lst[3] != numbers[3] and lst[3] != numbers[4]):
showcase = showcase + str("W,")
else:showcase = showcase + str("C,")
if lst[4] == numbers[0] or lst[4] == numbers[1] or lst[4] == numbers[2] or lst[4] == numbers[3]:
showcase = showcase + str("M,")
elif (lst[4] != numbers[0] and lst[4] != numbers[1] and lst[4] != numbers[2] and lst[4] != numbers[3] and lst[4] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
print("Status is:(",showcase,")")
if (lst[0] == numbers[0] and lst[1] == numbers[1] and lst[2] == numbers[2] and lst[3] == numbers[3] and lst[4] == numbers[4]):
print("Winner Winner chiken dinner")
猜谜游戏()
您可以先使用 qt designer 生成 GUI,然后将您的代码包含在其中。
pip install pyqt5-tools
我在 python 中写了一个简单的代码,我想为它制作一个图形用户界面,我想使用 pyqt5。 如何使用 pyqt5 将我的代码制作成图形用户界面? 不知道如何以及从哪里开始...... 有什么好的资源可以免费从头开始学习pyqt5吗?
顺便说一句,这是我的代码:
随机导入 定义重启(): return猜谜游戏()
def 猜谜游戏(): 数字= random.sample(范围(9),5)
print("instruction:")
print("Correct = C, Wrong= W, Missplaced = M")
print("there are no repeative digits.")
lst=[0,0,0,0,0,0,0,0,0]
while (lst[0] != numbers[0] or lst[1] != numbers[1] or lst[2] != numbers[2] or lst[3] != numbers[3] or lst[4] != numbers[4]):
g = int(input("Guess the five digit number:"))
lst = [int(y) for y in str(g)]
showcase = str()
if (lst[0] == numbers[1] or lst[0] == numbers[2] or lst[0] == numbers[3] or lst[0] == numbers[4]):
showcase= showcase + str("M,")
elif (lst[0] != numbers[0] and lst[0] != numbers[1] and lst[0] != numbers[2] and lst[0] != numbers[3] and lst[0] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
if (lst[1] == numbers[0] or lst[1] == numbers[2] or lst[1] == numbers[3] or lst[1] == numbers[4]):
showcase = showcase + str("M,")
elif (lst[1] != numbers[0] and lst[1] != numbers[1] and lst[1] != numbers[2] and lst[1] != numbers[3] and lst[1] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
if (lst[2] == numbers[0] or lst[2] == numbers[1] or lst[2] == numbers[3] or lst[2] == numbers[4]):
showcase = showcase + str("M,")
elif (lst[2] != numbers[0] and lst[2] != numbers[1] and lst[2] != numbers[2] and lst[2] != numbers[3] and lst[2] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
if (lst[3] == numbers[0] or lst[3] == numbers[1] or lst[3] == numbers[2] or lst[3] == numbers[4]):
showcase = showcase + str("M,")
elif (lst[3] != numbers[0] and lst[3] != numbers[1] and lst[3] != numbers[2] and lst[3] != numbers[3] and lst[3] != numbers[4]):
showcase = showcase + str("W,")
else:showcase = showcase + str("C,")
if lst[4] == numbers[0] or lst[4] == numbers[1] or lst[4] == numbers[2] or lst[4] == numbers[3]:
showcase = showcase + str("M,")
elif (lst[4] != numbers[0] and lst[4] != numbers[1] and lst[4] != numbers[2] and lst[4] != numbers[3] and lst[4] != numbers[4]):
showcase = showcase + str("W,")
else:
showcase = showcase + str("C,")
print("Status is:(",showcase,")")
if (lst[0] == numbers[0] and lst[1] == numbers[1] and lst[2] == numbers[2] and lst[3] == numbers[3] and lst[4] == numbers[4]):
print("Winner Winner chiken dinner")
猜谜游戏()
您可以先使用 qt designer 生成 GUI,然后将您的代码包含在其中。
pip install pyqt5-tools