我编写了一个 gui 剪刀石头布,并在按钮上使用了图像tkinter.ttk。我可以在通过空闲运行程序时打开程序,但是当我双击它时,它只会打开 cmd 一秒钟并且什么也不做
我都试过了from tkinter.ttk import *和from tkinter import ttk。我也将 python 安装到 PATH
from tkinter import *
from tkinter.ttk import *
import random
# rock button command
def clickrock():
Computer.config(text=f"Computer chose: {comp}")
if comp == "rock":
Answer.configure(text="You: DRAW")
elif comp == "paper":
Answer.configure(text="You: LOSE")
else:
Answer.configure(text="You: WIN")
rockButton.configure(state='disabled')
paperButton.configure(state='disabled')
scissorsButton.configure(state='disabled')
restart.place(x=160, y=150)
# paper button command
def clickpaper():
Computer.config(text=f"Computer chose: {comp}")
if comp == "rock":
Answer.configure(text="You: WIN")
elif comp == "paper":
Answer.configure(text="You: DRAW")
else:
Answer.configure(text="You: LOSE")
rockButton.configure(state='disabled')
paperButton.configure(state='disabled')
scissorsButton.configure(state='disabled')
restart.place(x=160, y=150)
# scissors button command
def click3():
Computer.config(text=f"Computer chose: {comp}")
if comp == "rock":
Answer.configure(text="You: LOSE")
elif comp == "paper":
Answer.configure(text="You: WIN")
else:
Answer.configure(text="You: DRAW")
rockButton.configure(state='disabled')
paperButton.configure(state='disabled')
scissorsButton.configure(state='disabled')
restart.place(x=160, y=150)
def click_restart():
restart.place_forget()
comp1 = random.randint(1,3)
Answer.config(text="You: ")
Computer.config(text="Computer chose: ")
rockButton.configure(state='normal')
paperButton.configure(state='normal')
scissorsButton.configure(state='normal')
#creates window
window = Tk()
window.title("rock paper scissors")
window.geometry("400x300")
我应该可以在没有空闲的情况下打开程序,其他代码可以在没有空闲的情况下打开,但这不能
慕容森
汪汪一只猫
紫衣仙女
相关分类