如何制作弹出按钮(Python)

时间:2017-03-18 18:51:37

标签: python

如何制作它如此弹出框(如果你有更好的名称,下面的评论)会出现问你一个问题。它会有一个按钮说我同意,另一个说我不同意。

1 个答案:

答案 0 :(得分:2)

我想这是一个简单的问题:

import tkinter as tk
root = tk.Tk()
questionsAsked = []

def yes():
    #do stuff if the user says yes
    pass

def no():
    #do stuff if the user says no
    pass

def modal(question):
    if question in questionsAsked:
        return False
    questionsAsked.append(question)

    label = tk.Label(root, text=question)

    bYes = tk.Button(root, text="Yes", command=yes)
    bNo = tk.Button(root, text="No", command=no)

    for el in [label, bYes, bNo]:
        el.pack()

modal("Do you want to continue?")
root.mainloop()