简体   繁体   English

阻止 Tkinter 网格改变大小

[英]Stop Tkinter grid from changing size

I have a music player that displays the song name in a Label, which is in a grid.我有一个音乐播放器,它在网格中的 Label 中显示歌曲名称。 My entire window resizes if a song is long enough, but it doesn't need to.如果歌曲足够长,我的整个 window 都会调整大小,但不需要。 Is there a way to either make a row that has one column in it, or a way to just make the window stop resizing?有没有办法让一行中有一列,或者让 window 停止调整大小?

self.search_results = tk.Label(master, text=self.query, bg="#eeac41", fg="#000000") 
self.search_results.grid(row=6, column=1)

You can make use of width and height if you want static size如果你想要 static 尺寸,你可以使用宽度和高度

self.search_results = tk.Label(master, text=self.query, height = 10,width = 40 bg="#eeac41", fg="#000000") 

Change the values of height and width as per your needs.根据您的需要更改高度和宽度的值。 You can specify only either of these if you want.如果需要,您可以只指定其中任何一个。

 # If you use padx and pady inside the label to set the size. For example : 
 self.search_results = tk.Label(master, text=self.query, bg="#eeac41", fg="#000000", 
 padx= 35, pady=25)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM