-2
A
回答
1
您可以使用Toplevel()
创建自己的消息窗口,那么你可以做你想做的。
import tkinter as tk
# --- functions ---
def about():
win = tk.Toplevel()
win.title("ABOUT")
l = tk.Label(win, text="One\ntwo two\nThree Three Three", bg='white')
l.pack(ipadx=50, ipady=10, fill='both', expand=True)
b = tk.Button(win, text="OK", command=win.destroy)
b.pack(pady=10, padx=10, ipadx=20, side='right')
# --- main ---
root = tk.Tk()
b = tk.Button(root, text="About", command=about)
b.pack(fill='x', expand=True)
b = tk.Button(root, text="Close", command=root.destroy)
b.pack(fill='x', expand=True)
root.mainloop()
的Linux:
BTW:你可以找到文件,消息框代码
import tkinter.messagebox
print(tkinter.messagebox.__file__)
,然后在编辑器中打开,看看它是怎么做的。
编辑:,你还可以创建MsgBox
类,并使用了很多次。
举例说明了如何更改类的一些元素:标签字体,按钮上的文字和位置
import tkinter as tk
# --- classes ---
# you can put this in separated file (it will need `import tkinter`)
import tkinter
class MsgBox(tkinter.Toplevel):
def __init__(self, title="MsgBox", message="Hello World"):
tkinter.Toplevel.__init__(self)
self.title(title)
self.label = tkinter.Label(self, text=message)
self.label['bg'] = 'white'
self.label.pack(ipadx=50, ipady=10, fill='both', expand=True)
self.button = tkinter.Button(self, text="OK")
self.button['command'] = self.destroy
self.button.pack(pady=10, padx=10, ipadx=20, side='right')
# --- functions ---
def about():
msg = MsgBox("ABOUT", "One\nTwo Two\nThree Three Three")
msg.label['font'] = 'Verdana 20 bold'
msg.button['text'] = 'Close'
msg.button.pack(side='left')
# --- main ---
root = tk.Tk()
b = tk.Button(root, text="About", command=about)
b.pack(fill='x', expand=True)
b = tk.Button(root, text="Close", command=root.destroy)
b.pack(fill='x', expand=True)
root.mainloop()
代码在GitHub上:furas/python-examples/tkinter/messagebox/own-messagebox
相关问题
- 1. Python Tkinter列表框对齐
- 2. tkinter askyesno消息框行为
- 3. ext.js消息框按钮对齐
- 4. Extjs消息框中心对齐
- 5. Tkinter的消息框askyesno starnge响应
- 6. Kivy等同于tkinter的消息框
- 7. Tkinter警告消息中的“不再显示消息”复选框
- 8. 在tkinter消息框中更改消息颜色的一部分
- 9. 左右对齐消息
- 10. Python tkinter 8.5导入消息框
- 11. tkinter删除一个消息框内容
- 12. 如何设置tkinter消息边框
- 13. 如何用tkinter创建消息框?
- 14. 对齐的标签,文本框和消息
- 15. tkinter textbox对齐图像
- 16. Python tkinter问题对齐
- 17. Tkinter网格对齐问题
- 18. 左右对齐消息气泡
- 19. android:如何在alertDialog中对齐消息?
- 20. 如何在alertdialog中对齐消息?
- 21. Python3 - Tkinter - 即时消息
- 22. 消息未打印Tkinter
- 23. 带有SDL的对话框/消息框?
- 24. WPF消息框与WinForms的消息框
- 25. 消息/确认对话框
- 26. 消息对话框错误
- 27. Python的填充串对齐列在Tkinter的列表框控件
- 28. 了多个文字的Python Tkinter的消息框
- 29. 单选框水平居中对齐的Tkinter
- 30. 删除Tkinter消息框背面的屏幕
你是什么意思“中心“?居中一行到另一行,在窗口矩形中居中文本?你总是可以创建自己的窗口(使用带'Label'的'tk.Toplevel'并对齐文本:[示例](https://github.com/furas/python-examples/tree/master/tkinter/align-grid-pack )。顺便说一句:它看起来像'\ n'后面有空格 – furas
https://i-msdn.sec.s-msft.com/dynimg/IC86459.jpeg看图片...我想要的文字是在中心。谢谢 –