Reputation: 39
I am trying to write a Program, in which u are able to open a seperate testing/debug window. Like, a second window including some buttons to affect the main window. I already tried a few things and i am able to open two seperate windows but whatever i am trying to draw is drawn in the main window.
import tkinter as tk
from tkinter import *
def debugWindow():
dbWin = tk.Tk()
dbWin.title("Debug")
btn = tk.Button(text="Test")
btn.pack()
dbWin.mainloop()
window = tk.Tk()
window.title("Mainwindow")
btn2 = tk.Button(text="Start debug Window", command=debugWindow)
btn2.pack()
window.mainloop()
So that's what i tried, but as i said the second button renders in the first window. Also i am pretty new to Python so if this is not the way u normally do it, please correct me. I am still learning :) And also sorry for my english, i am not a native speaker.
Upvotes: 1
Views: 1223
Reputation: 303
If you want to make the button stay on the window called dbWin ,then, instead of using:
btn = tk.Button(text="Test")
which python assumes that the button is suppose to go on the main window, use:
btn = tk.Button(dbWin, text="Test")
Using this will specifically assign the second parameter thus allowing your button to go on the window dbWin
(credit to those who said this before me in the comments)
Upvotes: 2