this is my main module(this is for a point of sale system)
from tkinter import *
from SettingsMenuPOS import *
from Globalvariables import *
root = Tk() #mainprogram
root.iconbitmap('D:/Gatlabs logo.ico')
opensettingsmenu = Button(root, text= "Open Settings", command = settingsmain)
root.title(Mname)
opensettingsmenu.grid(row= 0, column= 0)
enter_button = Button( root , text = "ENTER", padx = 20, pady = 10, command= EnterEvent)
enter_button.grid(row= 0, column= 1)
root.mainloop()
im importing a setting module which changes the title of the program
from Globalvariables import *
from tkinter import *
#Mart Name
#user accounts
def settingsmain():
settingmenu = Toplevel()
settingmenu.iconbitmap('D:/Gatlabs logo.ico')
global entryformartname
labelformartname = Label(settingmenu, text = "Enter name of your store")
entryformartname = Entry(settingmenu)
entryformartname.grid(row = 0, column = 0)
setmartname = Button(settingmenu, text = "setname", command = setname)
setmartname.grid(row= 0, column = 1)
settingmenu.mainloop()
def setname():
global Mname, entryformartname
Mname = entryformartname.get()
and im using a global variable Mname to display title of the program. ive set the variable Mname = "Gatlabs" and the user can change it through entry. but everytime i try to set the title it doesnt change:( i hope to get better at coding but i suck. pls help im stuck
I think the problem here is that you are thinking that using -:
root.title(var)
would make it so that anytime you change the var the title will change, but actually its that the title is changed only once and to the value of the var at the time it was supplied.
So if you want it to change everytime you change your var, then rather put it in the same function as the one where you change your var.
def update_title(title) :
global var
var = title
root.title(title)
return
and now every time you change the title run this down with the desired title as the argument.
I hope this solves your problem. Also i hope you're safe in the time of an ongoing pandemic.
Change setname
function like this:
def setname():
global Mname, entryformartname, setmartname
Mname = entryformartname.get()
parent_name = setmartname.winfo_parent()
parent = setmartname._nametowidget(parent_name)
parent.title(Mname)
In your code, you just update Mname
variable and window title stays unchanged.
You can get the master from button widget which is the window itself. Then, change its title.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.