Reputation: 21
I'm looking for a way to dynamically change the title.
Below is my source code.
root = Tk()
root.title('Title')
root.geometry('300x160')
root.resizable(False,False)
.
.
.
root.mainloop()
Is there any way?
Upvotes: 2
Views: 730
Reputation: 91
Just call root.title("Init title")
works in my case only once. For dynamic change I use wm_title
:
import tkinter as tk
root = tk.Tk()
...
root.wm_title("New title")
root.mainloop()
Upvotes: 0
Reputation: 4537
Walrus to rescue. Using Python 3.8+
import tkinter as tk
if i:=input('title is: '):
w=tk.Tk()
w.title(i)
w.mainloop()
Upvotes: 0
Reputation: 119
You can set a string variable.
import tkinter as tk
w=tk.Tk()
title='my_title'
w.title(title)
w.mainloop()
as I understand you want it to change automatically. Instead of 'my_title' you can use a user input or data from database.
Quick example with input:
import tkinter as tk
i=input('title is: ')
if i:
w=tk.Tk()
w.title(i)
w.mainloop()
Upvotes: 2