Я кодировал бумажные ножницы gui rock и использовал изображения на кнопках с 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")
# labels to give instructions
Label(window, text="rock paper scissors game").pack()
Label(window, text="pick a button").pack()
Computer = Label(window, text="Computer chose: ")
Computer.place(x=160, y=180)
#images
rock_photo = PhotoImage(file = "rock.png")
paper_photo = PhotoImage(file = "paper.png")
scissors_photo = PhotoImage(file = "scissors.png")
#buttons
rockButton = Button(window, image =rock_photo, command=clickrock)
paperButton = Button(window, image=paper_photo, command=clickpaper)
scissorsButton = Button(window, image = scissors_photo, command=click3)
restart = Button(window, text="RESTART", command=click_restart)
# pack buttons
rockButton.place(x=80, y=50)
paperButton.place(x=160, y=50)
scissorsButton.place(x=240, y=50)
# picking computer choice
comp1 = random.randint(1,3)
# naming comp choice
if comp1 == 1:
comp = "rock"
elif comp1 == 2:
comp = "paper"
elif comp1 == 3:
comp = "scissors"
# labels
Answer = Label(window, text="You: ")
Answer.place(x=160, y=200)
Я должен иметь возможность открывать программу без простоя, другой код может быть открыт без простоя, но это не может