Найти - Пользователи
Полная версия: Tkinter, переименовать пункт Menu
Начало » GUI » Tkinter, переименовать пункт Menu
1
Kemok
Добрый день!
Подскажите пожалуйста, возможно ли переименовать пункт меню? Не нашел информацию по этому поводу.
Пробовал вот так:
 menu_object.entryconfigure(index, label='new title')
Выдает ошибку:
 _tkinter.TclError: unknown option "-label"
4kpt_V
Более полный кусок кода хотелось-бы глянуть.
Kemok
Создание меню:
 LOC = {'settings': 'Settings',
        'path': 'Path to LoL',
        'lang': 'Language'}
gm = tk.Menu(root)
root.config(menu=gm)
sm = tk.Menu(gm, tearoff=0)
gm.add_cascade(label=LOC['settings'], menu=sm)
sm.add_command(label=LOC['path'], command=bge.path)
sm.add_command(label='API key', command=bge.setAPI)
lm = tk.Menu(sm, tearoff=0)
sm.add_cascade(label=LOC['lang'], menu=lm)
lm.add_command(label='English', command=en_loc)
lm.add_command(label='Русский', command=ru_loc)

В ходе программы LOC изменяется и хотелось бы чтобы пункты меню сменили свое название по средствам функций en_loc и ru_loc.
PEHDOM
You can use the postcommand callback to update (or even create) the menu every time it is displayed.
http://effbot.org/tkinterbook/menu.htm
както так:

 from tkinter import *
counter = 0
def update():
    global counter
    counter = counter + 1
    menu.entryconfig(0, label=str(counter))
root = Tk()
menubar = Menu(root)
menu = Menu(menubar, tearoff=0, postcommand=update)
menu.add_command(label=str(counter))
menu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="Test", menu=menu)
root.config(menu=menubar)
root.mainloop()
Kemok
Благодарю!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB