1
referwork = ttk.Notebook(root, style =".TNotebook")
f1 = ttk.Frame(referwork)
f2 = ttk.Frame(referwork)
referwork.add(f1, text="Search", padding = 1)
referwork.add(f2, text="Add/Delete", padding = 1)

#referwork.configure (height = 500, width = 800)
referwork.grid(row=0, column=0, sticky=(N,W,S,E))

我已经使用上面的方法创建了一个包含两个标签的笔记本。首先执行搜索。What I want to do is to have an alert in a message box appear messagebox.askyesno and when 'yes' is selected that the focus moves to the second page of the notebook

messagebox.askyesno(0.0,'"{0}"{1} \n {2}\n'.format(search_analyte.get(),' is  not in the database.','Add,if appropriate'))
        if True:

据我所知。我无法弄清楚如何使用此对话和条件“打开”第二页。非常感谢您的帮助

4

1 回答 1

1

使用Notebook.select(tab)方法,其中tab是笔记本子小部件之一。

from tkinter import *
from tkinter.ttk import *
from tkinter.messagebox import askyesno

def open_first():
    referwork.select(f1)
def open_second():
    if askyesno('Title', 'Press "Yes" to open second page') == YES:
        referwork.select(f2)

root = Tk()
referwork = Notebook(root, style =".TNotebook")
f1 = Frame(referwork)
f2 = Frame(referwork)
Button(f1, text='Go =>', command=open_second).pack(padx=100, pady=100)
Button(f2, text='<= Go', command=open_first).pack(padx=100, pady=100)
referwork.add(f1, text="Search", padding = 1)
referwork.add(f2, text="Add/Delete", padding = 1)
referwork.grid(row=0, column=0, sticky=(N,W,S,E))
root.mainloop()
于 2013-05-10T12:35:47.910 回答