10urc0de
10urc0de

Reputation: 21

How can I change title dynamically in tkinter?

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

Answers (3)

Andyrey
Andyrey

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

toyota Supra
toyota Supra

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

KKK
KKK

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

Related Questions