How to display text on a new window Tkinter? How to display text on a new window Tkinter? tkinter tkinter

How to display text on a new window Tkinter?


In your code you reset whatever rule_window is to a string (in this line: rule_window = rule_window.title(...))

Try this:

from import tkinter *window = Tk()window.title("Guessing Game")welcome = Label(window, text="Welcome To The Guessing Game!", background="black", foreground="white")welcome.grid(row=0, column=0, columnspan=3)def Rules():   rule_window = Toplevel(window)   rule_window.title("The Rules")   the_rules = Label(rule_window, text="Here are the rules...", foreground="black")   the_rules.grid(row=0, column=0, columnspan=3)rules = Button(window, text="Rules", command=Rules)rules.grid(row=1, column=0, columnspan=1)window.mainloop()

When you want to have 2 windows that are responsive at the same time you can use tkinter.Toplevel().


In your code, you have initialized the new instances of the Tkinter frame so, instead of you can create a top-level Window. What TopLevel Window does, generally creates a popup window kind of thing in the application. You can also trigger the Tkinter button to open the new window.

from tkinter import *from tkinter import ttk#Create an instance of tkinter windowroot= Tk()root.geometry("600x450")#Define a functiondef open_new():    #Create a TopLevel window    new_win= Toplevel(root)    new_win.title("My New Window")    #Set the geometry    new_win.geometry("600x250")    Label(new_win, text="Hello There!",font=('Georgia 15 bold')).pack(pady=30)#Create a Button in main Windowbtn= ttk.Button(root, text="New Window",command=open_new)btn.pack()root.mainloop()