2017-02-18 126 views
0

我嘗試過所有方法來設置tkinter消息部件邊框,但仍然收到任何效果。我想知道它是否沒有邊界屬性?但是我可以使用相同的代碼設置標籤和文本邊框。這裏是我的代碼片段:如何設置tkinter消息邊框

from tkinter import * 

root = Tk() 
frame = Frame(root) 
message = Message(frame, text="hello world", width=200) 
message.config(fg="red", borderwidth=100, highlightcolor="green") 
frame.pack() 
message.pack() 

root.minsize(300, 200) 
root.mainloop() 

這就是結果:

result without green border

OS版本:OS X 10.11.4

Python版本:3.52

+0

沒有一個'border'屬性,但確實有'borderwidth' http://effbot.org/tkinterbook/message.htm#Tkinter.Message.config-method,嘗試'borderwidth = 200' – davedwards

+0

沒有任何意義,我已經試過這樣的方式 – Crabime

+0

什麼沒有意義?它說'borderwidth =邊框寬度。默認值是2.(borderWidth/BorderWidth)'我在你的代碼中試過了,我得到了這樣一個邊框 – davedwards

回答

1

你設置邊框寬度正確。問題在於,您無法看到正在執行的更改,直到您添加background顏色並更改FrameMessage小部件的relief。現在嘗試使用此修訂後的代碼更改邊框寬度,並且我相信您會收到「陷阱」時刻。

from tkinter import * 

root = Tk() 
frame = Frame(root, background='yellow', borderwidth=20, relief=RAISED) 
message = Message(frame, text="hello world", width=200) 
message.config(fg="red", borderwidth=50, highlightcolor="green", 
       background='light blue', relief=SUNKEN) 
frame.pack() 
message.pack() 

root.minsize(300, 200) 
root.mainloop() 

result

+0

好的,我明白了。 TKS – Crabime