21-Adicionar separador por Abas:
Para criar um controle por abas, são necessarios realizar 3 tarefas
- 1 - Criar um controle de abas usando a classe notebook
- 2 - criar as abas usando a classe Frame
- 3 -Adicionar as abas ao controle de abas.
- E por fim adicionar as abas no controle de abas para torna-las visíveis
- Exemplo:
from tkinter import *
from tkinter import ttk
window = Tk()
window.title("Ti Fora da Caixa")
window.geometry('350x200')
tab_control = ttk.Notebook(window)#1
aba1 = ttk.Frame(tab_control)#2
tab_control.add(aba1, text='Aba 1')#3
tab_control.pack(expand=1, fill='both')
window.mainloop()
from tkinter import * from tkinter import ttk window = Tk() window.title("Ti Fora da Caixa") window.geometry('350x200') tab_control = ttk.Notebook(window)#1 aba1 = ttk.Frame(tab_control)#2 tab_control.add(aba1, text='Aba 1')#3 tab_control.pack(expand=1, fill='both') window.mainloop()
E o resultado sera esse:
###############################################################
###############################################################
21.1 Adicionar widgets as abas:
Neste Exemplo adicionei duas labels em duas abas diferentes:
from tkinter import * from tkinter import ttk window = Tk() window.title("Ti Fora da Caixa") window.geometry('350x200')
tab_control = ttk.Notebook(window) aba1 = ttk.Frame(tab_control) aba2 = ttk.Frame(tab_control) tab_control.add(aba1, text='Primeira Aba') tab_control.add(aba2, text='Segunda Aba') lbl1 = Label(aba1, text= 'Label Aba1') lbl1.grid(column=0, row=0) lbl2 = Label(aba2, text= 'Label Aba2') lbl2.grid(column=0, row=0) tab_control.pack(expand=1, fill='both') window.mainloop()
from tkinter import * from tkinter import ttk window = Tk() window.title("Ti Fora da Caixa") window.geometry('350x200') tab_control = ttk.Notebook(window) aba1 = ttk.Frame(tab_control) aba2 = ttk.Frame(tab_control) tab_control.add(aba1, text='Primeira Aba') tab_control.add(aba2, text='Segunda Aba') lbl1 = Label(aba1, text= 'Label Aba1') lbl1.grid(column=0, row=0) lbl2 = Label(aba2, text= 'Label Aba2') lbl2.grid(column=0, row=0) tab_control.pack(expand=1, fill='both') window.mainloop()
1 Comentários
cara me ajudou muito tá
ResponderExcluir