[英]Tkinter Button not resizing correctly according to the font size on a Mac
[英]Resizing a Button in tkinter on a Mac
我還是tkinter
新手,並注意到當我嘗試使用來增加按鈕的大小時
button.config(height=20, width=50)
它根本沒有用。 在紫羅蘭色的背景下,這只是空白區域的巨大區域,在空白區域的中間是按鈕。 但是,如果我單擊空白區域內的任何地方,它將起作用並執行其命令。
這是代碼:
from tkinter import *
root = Tk()
def cheese():
print ('hi')
logo = PhotoImage('../Desktop/logothing.gif')
explanation = """Flaming Arrows whizz over your hair, War rages around you. Suddenly,
it charges into you. A 8 foot tall mechanical beast the enemy have been training for war.
You have no chance but to fight it. You swing your sword as hard as you can...Only to
leave a minor dent on it's armor. With one blow from its club, you fall unconscious."""
w2 = Label(root, justify=LEFT, text=explanation, image = logo,
compound = CENTER, fg="blue", bg= "Violet",
font="ComicSansMS 32 bold",padx=1000, pady=1000).pack(side='left')
w1 = Button(root, text = 'Hello',command = cheese, padx=10)
w1.config(height=20, width = 50)
w1.place(x=500, y=500)
我已經在Mac上進行了測試,看來您無法調整按鈕的高度(它的工作原理就像是pady
),只能調整寬度。 實際上,如果將按鈕的高度減小到1,您將得到以下內容:
我可以看到的唯一解決方法是增加字體的大小。 如果使用pady
,則將垂直增加包含按鈕的白框。
正如Bryan Oakley在評論中提到的那樣,這可能是特定於平台的問題。
增加字體大小不起作用。 這是我嘗試時遇到的問題,因為遇到同樣的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.