使用tkinter将按钮窗口小部件集中在列中



我有一个labelframe,在该labelframe内部,我放了一个按钮。该按钮将始终出现在Labelframe的左上角,尽管我希望它以Labelframe为中心。我缺少哪个属性,将迫使此按钮将自己居中在Labelframe内?

self.f1_section_frame=LabelFrame(self.mass_window, text="LOCATIONS", width=300, height=998, padx=5, pady=5, bd=5)
self.f1_section_frame.grid(row=0, rowspan=6, column=1, sticky="nw", padx=(2,0))
self.f1_section_frame.grid_propagate(False)
self.button_frame1 = LabelFrame(self.f1_section_frame, width=275, height=50)
self.button_frame1.grid_propagate(False)
self.button_frame1.grid(row=1, column=0)
self.b1_scoring=Button(self.button_frame1, text="CONFIRMnLOCATION(S)", height=2, width=10, command=self.initiate_site_scoring, justify="center")
self.b1_scoring.grid(row=0,column=0, pady=(1,0))

感谢您的响应 @r4ph43l。我给了一个镜头,似乎没有改变。但是,这让我思考了,所以我从包围我的按钮的框架上删除了" grid_propagate",然后将框架包裹在框架周围,而没有任何空间,并将其放置在其放置的列中的框架中心。然后,我在我的最左键的最左键上使用了padx =(x,0(,在我的最右键上使用padx =(0,x(,添加左侧和右侧所需的空间,并且它正在奏效我现在需要它。

self.f1_section_frame=LabelFrame(self.mass_window, text="LOCATIONS", width=300, 
height=998, padx=5, pady=5, bd=5)
self.f1_section_frame.grid(row=0, rowspan=6, column=1, sticky="nw", padx=(2,0))
self.f1_section_frame.grid_propagate(False)
self.button_frame1 = LabelFrame(self.f1_section_frame, width=275, height=50)
self.button_frame1.grid(row=1, column=0)
self.b1_scoring=Button(self.button_frame1, text="CONFIRMnLOCATION(S)", height=2, width=10, 
command=self.initiate_site_scoring, justify="center")
self.b1_scoring.grid(row=0,column=0, padx=(15,0))
self.b2_scoring=Button(self.button_frame1, text="CLEARnSELECTION(S)", height=2, 
width=10, command=self.clear_selected_locations)
self.b2_scoring.grid(row=0,column=1)
self.b3_scoring=Button(self.button_frame1, text="UPDATEnSELECTION(S)", height=2, width=10, 
command=self.update_selected_location_details)
self.b3_scoring.grid(row=0,column=2, padx=(0,15))

最新更新