Reputation: 65
I'm new to tkinter in python and am not able to figure out what the syntax below does exactly.
oldtitle=window.newtitle()
Removing this line from the code doesn't makes any difference to the output.
from tkinter import *
from tkinter import ttk
root=Tk()
root.title('to')
main=Toplevel(root)
tk=main.title()#<---this line
main.title('hello world')
mainloop()
Upvotes: 2
Views: 4311
Reputation: 22724
What the line tk=main.title()
does is to get the title of main
.
Here is a demo using your own code:
from tkinter import *
from tkinter import ttk
root=Tk()
root.title('to')
main=Toplevel(root)
main.title('hello world')
tk=main.title() # Note I moved this line to here
print(tk) # This will print 'hello world'
mainloop()
The line print(tk)
will print the title of main
which is hello world.
If you want to set a different title then use this synatax instead: tk = main.title('Some new title')
(or simply main.title('Some new title')
if you do not need to save the title string into an other variable):
from tkinter import *
from tkinter import ttk
root=Tk()
root.title('to')
main=Toplevel(root)
main.title('hello world')
tk=main.title('Some new title') # or simply: main.title('Some new title')
mainloop()
Output:
Note: avoid using tk
as your personal variable name because the recommended way to import tkinter
is: import tkinter as tk
Upvotes: 3