How to Change Tkinter Frame Title?


Tkinter window is the native component of tkinter application that contains some frames, a group of widgets, and some other elements. A Tkinter frame has a group of too many widgets.

Let us suppose that we have created a frame with some widgets and now we want to rename the title of the application. Frame titles are a necessary part of any application. We can change the title of the frame using the title("title") method.

Example

In this example, we will create an application that will contain an entry widget and a button. The button is used to rename the title of the window. Initially, we will create an instance of StringVar() and this can be used to capture the user input in the Entry widget. Then, by using the set() method, we will pass the captured variable to set the title of the frame.

#Import tkinter library
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the Geometry
win.geometry("750x250")
#Define a Variable to accept the input
var= StringVar()
#Define a function to change the title
def change_title():
win.title(var.get())
#Create an Entry widget
text=Entry(win,textvariable=var)
text.focus_set()
text.pack(pady=20)
#Pass the title in the function
var.set(win.title())
#Create a Button
Button(win, text= "Change", command= change_title).pack(pady=20)
win.mainloop()

Output

By running the above code, we can display a window that contains a button and the frame object. Now, whenever we write some title in the entry widget and click the “Change” button, it will change the title of the frame.

Now, change the title of the frame by writing some text in the Entry widget and click the “Change” to display the reflected output.

Updated on: 15-Apr-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements