in my code I implemented, that with a click of a button a new window should open. In this window I have some widgets along with a button to close the window again. Tis works just fine. The problem is, that after closing the window, I am not able to open it again. There is no Errormessage it just won’t work anymore (along with some other buttons that worked before).
The problem is the folloing code:
global window_edit_point
.
.
.
def edit_point(i):
global window_edit_point, entry_edit_x, entry_edit_y, entry_edit_z
j = i
root.update_idletasks()
window_edit_point = tk.Tk()
x_window = root.winfo_x() + (root.winfo_width() // 2) - (300 // 2)
y_window = root.winfo_y() + (root.winfo_height() // 2) - (150 // 2)
window_edit_point.geometry("300x150+"+str(x_window)+"+"+str(y_window))
window_edit_point.configure(bg=bg_color)
window_edit_point.resizable(width=False, height=False)
window_edit_point.title("edit point")
window_edit_point.update_idletasks()
label_entry_edit_x = tk.Label(window_edit_point, text="x:", bg=bg_color)
label_entry_edit_x.place(x=10, y=0)
label_entry_edit_y = tk.Label(window_edit_point, text="y:", bg=bg_color)
label_entry_edit_y.place(x=130, y=0)
label_entry_edit_z = tk.Label(window_edit_point, text="z:", bg=bg_color)
label_entry_edit_z.place(x=250, y=0)
entry_edit_x = tk.Entry(window_edit_point, width=15)
entry_edit_x.place(x=25, y=0)
entry_edit_y = tk.Entry(window_edit_point, width=15)
entry_edit_y.place(x=145, y=0)
entry_edit_z = tk.Entry(window_edit_point, width=15)
entry_edit_z.place(x=265, y=0)
button_point_edit = tk.Button(window_edit_point, width=50, text="update point", command=lambda: update_point(j))
button_point_edit.place(x=0, y=24)
def update_point(j):
global window_edit_point, entry_edit_x, entry_edit_y, entry_edit_z
x = int(entry_edit_x.get())
y = int(entry_edit_y.get())
z = int(entry_edit_z.get())
list_points[j][0] = x
list_points[j][1] = y
list_points[j][2] = z
draw_points()
window_edit_point.destroy()
I’ve tried to isolate the problem, but there it worked fine:
import tkinter as tk
root = tk.Tk()
root.geometry("500x500")
root.update_idletasks()
global new_win
def new_window():
global new_win
new_win = tk.Tk()
button2 = tk.Button(new_win, text="close", command=close)
button2.pack()
def close():
global new_win
new_win.destroy()
button1 = tk.Button(root, text="new_window", command=new_window)
button1.pack()
root.mainloop()
Can someone please help me what I did diffrent/wrong?
Thanks in advance!
CyberTigerhai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.