Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkinter在一个框架内拉伸小部件_Python_User Interface_Tkinter_Raspbian - Fatal编程技术网

Python tkinter在一个框架内拉伸小部件

Python tkinter在一个框架内拉伸小部件,python,user-interface,tkinter,raspbian,Python,User Interface,Tkinter,Raspbian,我目前正在尝试制作一个基本的GUI,在一个框架内,屏幕底部有5个按钮。我目前在一个框架中有两个按钮。这架行李被包装到底部。我想让这两个按钮填满画面 ##IMPORTS-------------------------------------------- from tkinter import * import tkinter.font ##GUIWindow------------------------------------------ window = tkinter.Tk()

我目前正在尝试制作一个基本的GUI,在一个框架内,屏幕底部有5个按钮。我目前在一个框架中有两个按钮。这架行李被包装到底部。我想让这两个按钮填满画面

##IMPORTS--------------------------------------------
from tkinter import *
import tkinter.font
##GUIWindow------------------------------------------
window = tkinter.Tk()                   
screen_w = window.winfo_screenwidth()  
screen_h = window.winfo_screenheight()
window.geometry('%dx%d' % (screen_w, screen_h))
window.title("betaV00")
myFont = tkinter.font.Font(family = 'Helvetica', size = 12, weight = "bold")
##WIDGET_BottomButtons---------------------------------
h=6
bot_frame = Frame(window, height = int(screen_h/10), width = int(screen_w))
bot_frame.pack(side=BOTTOM)

btn_HOME = Button(bot_frame, text="Home", font=myFont, bg='green', fg='white', height=h)
btn_HOME.grid(row = 0, column = 0)
btn_LEDS = Button(bot_frame, text="LEDS", font=myFont, bg='black', fg='green', height=h)
btn_LEDS.grid(row = 0, column = 1)

bot_frame.columnconfigure(0, weight=1)
bot_frame.columnconfigure(1, weight=1)
##-----------------------------------------------------

window.mainloop()
如果按钮不在框架中,我可以让它工作。目前正在发生的是这两个按钮不是伸展,并放置在中间并排。我可以/应该做些什么来扩展这些按钮?

这是因为两个按钮小部件所在的框架没有给出任何关于它应该占用多少父窗口的指示,因此它只是扩展到它可以容纳所有子窗口的最小大小

在本例中,如果您希望它们仅在x轴上展开(我假设您按照给定的静态高度进行展开),则需要将fill=x属性添加到框架bot_框架上的.pack命令中,并将sticky=NESW属性添加到两个按钮小部件上的.pack命令中

如下所示:

##IMPORTS--------------------------------------------
from tkinter import *
import tkinter.font
##GUIWindow------------------------------------------
window = tkinter.Tk()                   
screen_w = window.winfo_screenwidth()  
screen_h = window.winfo_screenheight()
window.geometry('%dx%d' % (screen_w, screen_h))
window.title("betaV00")
myFont = tkinter.font.Font(family = 'Helvetica', size = 12, weight = "bold")
##WIDGET_BottomButtons---------------------------------
h=6
bot_frame = Frame(window)
bot_frame.pack(side=BOTTOM, fill="x") #here

btn_HOME = Button(bot_frame, text="Home", font=myFont, bg='green', fg='white', height=h)
btn_HOME.grid(row = 0, column = 0, sticky="NESW") #here
btn_LEDS = Button(bot_frame, text="LEDS", font=myFont, bg='black', fg='green', height=h)
btn_LEDS.grid(row = 0, column = 1, sticky="NESW") #and here

bot_frame.columnconfigure(0, weight=1)
bot_frame.columnconfigure(1, weight=1)
##-----------------------------------------------------

window.mainloop()
以上内容应能达到您的预期效果