Menu in the Tkinter Python module

Asked

Viewed 714 times

0

Hello, I have a screen that was made in Tkinter and I have a menu with cascade submenus, what I need to do is show the different information of the submenus without having to create several other screens using functions. Is it possible? If so, how? Follow the code below:

beginning

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)

tela_config()

1 answer

0

What do you mean? a menu inside a menu? That’s pretty 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)
  • I was thinking of creating different screens to show the different contents, for example, in the edit part of the menu, I need to put other buttons, other text entries for the user to be able to edit the login or the name, etc...

  • has the way for you to erase everything you have on your screen and do over what you want with . Destroy or create a new Tk for another window

Browser other questions tagged

You are not signed in. Login or sign up in order to post.