简体   繁体   中英

How can i change tab with button in tkinter?

from tkinter import *
from tkinter import ttk

root = Tk()
root.geometry("200x200")
Tabs = ttk.Notebook(main)
Tabs.pack(side = "top", expand = 1, fill = "both", padx = 10, pady = 10)



tab1 = ttk.Frame(Tabs)
Tabs.add(tab1, text = "Registration")
tab2 = ttk.Frame(Tabs)
Tabs.add(tab2, text = "All Students")
tab3 = ttk.Frame(Tabs)
Tabs.add(tab3, text = "Lectures")

def newtab():
    #open tab2


b1 = Button(tab1, text = "show tab2", command = newtab)
b1.grid(row = 2, column = 1)

root.mainloop()

So this my code, and what i wanna do is that when b1 is clicke for it to go to tab2 itselfe.

ps i tried ttk.Notebook.select(tab2) and it didnt work

Choose a ttk.Notebook instance to use select(tab_id) . In your code,Use

def newtab():
    Tabs.select(tab2) # should be a instance of ttk.Notebook.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM