-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看圖片...我想要的文字是在中心。謝謝 –