【问题标题】:tkinter messagebox link to notebook pagetkinter 消息框链接到笔记本页面
【发布时间】:2013-05-10 12:16:53
【问题描述】:
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:

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

【问题讨论】:

    标签: python-3.x tkinter


    【解决方案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()
    

    【讨论】:

    • 谢谢。如果为真,则使用:open_second()
    猜你喜欢
    • 2019-01-03
    • 1970-01-01
    • 2014-06-14
    • 2014-04-01
    • 2015-03-29
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    相关资源
    最近更新 更多