bad window path name tkinter

I am trying to code rock paper scissors in tkinter python but my reset button command gives me the error:

Traceback (most recent call last):
  File "C:Python36libtkinter__init__.py", line 1699, in __call__  
    return self.func(*args)
  File "c:/Users/---------/OneDrive - -------------/python/rock paper scissors.py", line 26, in reset
    run()
  File "c:/Users/-----------/OneDrive - ---------------/python/rock paper scissors.py", line 186, in run
    choose_player_number()
  File "c:/Users/--------------/OneDrive - -----------------/python/rock paper scissors.py", line 181, in choose_player_number
    one_player.grid(column= 2, row=1)
  File "C:Python36libtkinter__init__.py", line 2220, in grid_configure
    + self._options(cnf, kw))
_tkinter.TclError: bad window path name ".!button5"
PS C:UsersN.Westrich> 

I don’t know how to access the tkinter library, so i don’t know what is throwing the program off.
My code is here:

import random
import tkinter as tk
from tkinter import *

window = tk.Tk()
window.geometry("1400x860")
window.title = "Rock paper scissors"

result = Label(window, text= "result will appear here", bg="green")
player_number = ""
list_of_integers = ["1", "2", "3"]

title = Label(window, text = "Rock paper scissors" , bg= "blue", fg = "white", font= "Times")
title.grid(column=3, row=0)

def reset():
    filler.destroy
    filler2.destroy
    filler3.destroy
    title.destroy
    result.destroy
    rock.destroy
    paper.destroy
    scissors.destroy
    reset1.destroy
    run()

reset1 = Button(window, text = "Reset", command= reset, fg="blue", bg = "yellow")

def evaluate_rock():
    global computer_input
    if computer_input == "3":
        win()
    elif computer_input == "2":
        loose()
    else:
        draw()

def evaluate_scissors():
    global computer_input
    if computer_input == "2":
        win()
    elif computer_input == "1":
        loose()
    else:
        draw()

def evaluate_paper():
    global computer_input
    if computer_input == "1":
        win()
    elif computer_input == "3":
        loose()
    else:
        draw()

def computer_choice(input):
    global computer_input
    computer_input = random.choice(list_of_integers)
    if computer_input == "1":
        computer_value = "Rock"
    elif computer_input == "2":
        computer_value = "paper"
    else:
        computer_value = "scissors"
    computer_result = Label(window, text= "the computer's choice was: " + computer_value , fg = "blue", bg = "green")
    computer_result.grid(column=3, row=3)
    if input == "rock":
        evaluate_rock()
    elif input == "scissors":
        evaluate_scissors()
    else:
        evaluate_paper()
    return computer_input

rock = Button(window, text="Rock", command= lambda: computer_choice("rock"), fg="green", bg="blue")
scissors = Button(window, text="Scissors", command = lambda: computer_choice("scissors"), fg = "black", bg = "blue")
paper = Button(window, text="paper", command = lambda: computer_choice("paper"), fg = "green", bg = "blue")

player_1 = Label(window, text = "Player 1", fg = "blue", bg = "red")
player_2 = Label(window, text= "Player 2", fg= "blue", bg= "red")

def evaluate():
    if player1input == player2input:
        result.configure(text= "Draw")
    elif player1input == "rock" and player2input == "scissors":
        result.configure(text= "Player 1 wins")
    elif player1input == "rock" and player2input == "paper":
        result.configure(text= "player 2 wins")
    elif player2input == "rock" and player1input == "scissors":
        result.configure(text= "Player 2 wins")
    elif player2input == "rock" and player1input == "paper":
        result.configure(text= "Player 1 wins")
    elif player1input == "paper" and player2input == "scissors":
        result.configure(text= "player 2 wins")
    elif player2input == "paper" and player1input == "scissors":
        result.configure(text= "Player 1 wins")
    reset1.grid(column= 3, row= 5)

def player_2_input(p2i):
    global player2input 
    player2input = p2i
    rock.destroy
    paper.destroy
    scissors.destroy
    player_2.destroy
    evaluate()
    return player2input

def player2():
    player_1.destroy
    player_2.grid(column= 3, row= 2)
    rock.configure(command = lambda: player_2_input("rock"))
    paper.configure(command= lambda: player_2_input("paper"))
    scissors.configure(command= lambda: player_2_input("scissors"))

def player_1_input(p1i):
    global player1input
    player1input = p1i
    player2()
    return player1input

def win():
    result.configure(text= "You Win")
    reset1.grid(column= 3, row= 5)

def loose():
    result.configure(text= "You loose")
    reset1.grid(column= 3, row= 5)

def draw():
    result.configure(text= "Draw")
    reset1.grid(column= 3, row= 5)

def place_buttons():
    result.grid(column=3, row=1)
    if player_number == 1:
        rock.grid(column=2, row=2)
        scissors.grid(column = 4, row=2)
        paper.grid(column = 3, row=2)
    elif player_number == 2:
        player_1.grid(column= 3, row= 2)
        rock.configure(command = lambda: player_1_input("rock"))
        paper.configure(command= lambda: player_1_input("paper"))
        scissors.configure(command= lambda: player_1_input("scissors"))
        rock.grid(column=2, row=3)
        scissors.grid(column = 4, row=3)
        paper.grid(column = 3, row=3)

one_player = Button(window, text = "One Player", command = lambda: [oneplayer(), place_buttons()])
two_players = Button(window, text= "Two players", command = lambda: [twoplayers(), place_buttons()])

def oneplayer():
    title.configure(text = "One player")
    title.grid(column=3, row=0)
    global player_number
    player_number = 1
    one_player.destroy()
    two_players.destroy()

def twoplayers():
    title.configure(text = "Two players")
    title.grid(column=3, row=0)
    global player_number
    player_number = 2
    one_player.destroy()
    two_players.destroy()

def add_fillers():
    global filler
    filler = Label(window, text = "                                                                   ")
    filler.grid(column=1, row=0)
    global filler2
    filler2 = Label(window, text = "                                                                   ")
    filler2.grid(column=0, row=0)
    global filler3
    filler3 = Label(window, text = "                                       ")
    filler3.grid(column=2, row=0)

def choose_player_number():
    one_player.grid(column= 2, row=1)
    two_players.grid(column= 4, row=1)

def run():  
    add_fillers()
    choose_player_number()

run()

window.mainloop()

I didn’t find any solutions online since they were all case specific.

If someone has a solution i would love to know how to finally complete the code.

New contributor

neo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

9

You destroy the two buttons one_player and two_players inside oneplayer() and twoplayers(), so when choose_player_numbers() is executed again by clicking reset1 button, exception will be raised.

Change the lines:

one_player.destroy()
two_players.estroy()

inside oneplayer() and twoplayers() to:

one_player.grid_forget()
two_players.grid_forget()

Note that even fixing this issue, your code still have other issues.

2

Can you try the rename your window path name from the tkinter library ‘init.py’ file.
I think it will help to you or you can use the ‘_’ behind of your path name words.

1

Your import:

import tkinter as tk

Therefore your Buttons, Labels, and other widgets are named e.g. tk.Label(….):

reset1 = tk.Button(window, text = "Reset", command= reset, fg="blue", bg = "yellow")

I recommend you to read the doc

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật