I'm a beginner in Python, I need help. How to make the robot to choose 1, 2 or 3 and display it.
Here Is my Script.
from tkinter import * from time import time import random
window = Tk() window.geometry('400x300')
sticks = 20
def computer(): global sticks
delete_sticks = random.randint(1, 3)
sticks = delete_sticks
def player(): global sticks
delete_sticks = int(entry_sticks.get())
if delete_sticks in [1,2,3]:
sticks -= delete_sticks
label_sticks.config(text="|"*sticks)
status.config(text=sticks)
if sticks == 1:
status.config(text='YOU WON!', fg='Green')
else:
window.after(200, computer)
Label_move.config(text='Computers turn, please wait.')
Label_move = Label(text='Type in a number from 1 to 3', font=('Arial', 15,'bold')) Label_move.pack()
emptyspace1 = Label() emptyspace1.pack()
entry_sticks = Entry(font=('Arial', 15,'bold')) entry_sticks.pack()
emptyspace2 = Label() emptyspace2.pack()
label_sticks = Label(text = sticks*'|', font = ('Arial', 30,'bold')) label_sticks.pack()
emptyspace3 = Label() emptyspace3.pack()
status = Label(text = '0', font=('Arial', 30, 'bold')) status.pack()
button = Button(text = 'Take sticks', font=('Arial', 15, 'bold'), command = player) button.pack()
window.mainloop()
Aucun commentaire:
Enregistrer un commentaire