Menu in the Tkinter Python module

0

Hello, I have a screen that was made in Tkinter and I have a menu with cascading submenus, what I need to do is show the different submenus information without having to create several other screens using functions. It's possible? If yes, how? Here is the code below:

home

from tkinter import *

def donothing():
    print("OH yeah")

def tela_config():
    global janela_config
    janela_config = Tk()
    janela_config.geometry("400x400+600+300")
    janela_config.title("Configurações")

MENU

barra_menu = Menu(janela_config)
janela_config.config(menu = barra_menu)

menu_versao = Menu(barra_menu)
barra_menu.add_cascade(label = "Versão", menu = menu_versao)
menu_versao.add_command(label = "Sobre", command = donothing)
menu_versao.add_separator()
menu_versao.add_command(label = "Sair", command = donothing)

menu_editar = Menu(barra_menu)
barra_menu.add_cascade(label = "Editar", menu = menu_editar)
menu_editar.add_command(label = "Login", command = donothing)
menu_editar.add_command(label = "Email", command = donothing)
menu_editar.add_command(label = "Senha", command = donothing)
menu_editar.add_command(label = "Função", command = donothing)

menu_ajuda = Menu(barra_menu)
barra_menu.add_cascade(label = "Ajuda", menu = menu_ajuda)
menu_ajuda.add_command(label = "Manual", command = donothing)
menu_ajuda.add_separator()
menu_ajuda.add_command(label = "Contato", command = donothing)

FIM_MENU

lb1 = Label(janela_config, text = "Nome:", font = "Arial 16")
lb2 = Label(janela_config, text = "Login:", font = "Arial 16")
lb3 = Label(janela_config, text = "Email:", font = "Arial 16")
lb4 = Label(janela_config, text = "Senha:", font = "Arial 16")
lb5 = Label(janela_config, text = "Função:", font = "Arial 16")
lb6 = Label(janela_config, text = "Data:", font = "Arial 16")
lb7 = Label(janela_config, text = "ID:", font = "Arial 16")

lb1.place(x = 0, y = 0)
lb2.place(x = 0, y = 30)
lb3.place(x = 0, y =60)
lb4.place(x = 0, y = 90)
lb5.place(x = 0, y = 120)
lb6.place(x = 0, y = 150)
lb7.place(x = 0, y = 180)

screen_config ()

    
asked by anonymous 06.12.2018 / 02:29

1 answer

0

What do you mean? a menu within a menu? This is very simple.

from tkinter import*
janela = Tk()
def comando():
     print('apertou')
itens_menu = Menu(janela)
itens_menu2 = Menu(janela, tearoff = 0)
submenu_nome = Menu(janela, tearoff = 0)
submenu_emails = Menu(janela, tearoff = 0)
itens_menu2.add_cascade(label = 'Nomes', menu = submenu_nome)
itens_menu2.add_cascade(label = 'Emails', menu = submenu_emails)
submenu_nome.add_command(label = 'Matheus', command = comando)
submenu_nome.add_command(label = 'João', command = comando)
submenu_emails.add_command(label = '[email protected]', command = comando)
submenu_emails.add_command(label = '[email protected]', command = comando)
itens_menu.add_cascade(label = 'Menu', menu = itens_menu2)
    
06.12.2018 / 02:52