[英]How to create a pop up message button with a value using tkinter in Python 3?
我正在尝试在 Python 中创建一个弹出消息,我可以创建自己的按钮名称并将它们设置为一个值任何建议如何? 例如:是= 1,否= 2,仅限商店= 3
msg = 'There was a problem data.'
tkinter.messagebox.showerror("Error!",msg)
这一切我现在有什么建议吗?
tkinter中有一个SimpleDialog
tkinter.simpledialog
模块可以用于你的情况:
import tkinter as tk
from tkinter.simpledialog import SimpleDialog
root = tk.Tk()
def show_message():
dlg = SimpleDialog(root, title='Error!', text='There was a problem data!',
buttons=['Yes', 'No', 'Stores Only'])
answer = dlg.go()
# answer = 0 for yes, 1 for No and 2 for 'Stores Only'
# i.e answer is the index of the button in buttons
print(answer)
btn = tk.Button(root, text='Show Message', command=show_message)
btn.pack()
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.