Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://habr.com/ru/sandbox/149940/
- import tkinter
- import random
- STICKS = 20
- def c1():
- global STICKS
- STICKS -= 1
- label1.config(text="| " * STICKS)
- if STICKS <= 0:
- label1.config(text=" " * 3 + "Компьютер победил!", foreground="red")
- return None
- computer_turn()
- def c2():
- global STICKS
- STICKS -= 2
- label1.config(text="| " * STICKS)
- if STICKS <= 0:
- label1.config(text=" " * 3 + "Компьютер победил!", foreground="red")
- return None
- computer_turn()
- def c3():
- global STICKS
- STICKS -= 3
- label1.config(text="| " * STICKS)
- if STICKS <= 0:
- label1.config(text=" " * 3 + "Компьютер победил!", foreground="red")
- return None
- computer_turn()
- def computer_turn():
- global STICKS
- choice = random.randint(1, 3)
- STICKS -= choice
- label1.config(text="| " * STICKS)
- if STICKS <= 0:
- label1.config(text=" " * 7 + "Игрок победил!", foreground="green")
- print(f"Компьютер убрал {choice} палочек")
- window = tkinter.Tk()
- window.geometry("550x200")
- window.title("Палочки")
- window.resizable(False, False)
- window.iconbitmap("stick.ico")
- text1 = tkinter.Label(window, text="Сколько палочек будете брать?")
- text1.pack()
- button1 = tkinter.Button(window, text="1", command=c1)
- button1.place(x=210, y=30)
- button2 = tkinter.Button(window, text="2", command=c2)
- button2.place(x=265, y=30)
- button3 = tkinter.Button(window, text="3", command=c3)
- button3.place(x=320, y=30)
- label1 = tkinter.Label(window, text="| " * STICKS, font=("Arial Bold", 30))
- label1.place(x=50, y=70)
- button4 = tkinter.Button(window, text="Ход компьютера", command=computer_turn)
- button4.place(x=220, y=150)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement