[英]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.