定位包含按钮的框架
Postitioning a frame that includes a button
如标题所示,我想在屏幕右上角放置一个包含 button
的 frame
...我会给你们两张图片unterstanding,在第一张图片中,您会注意到一个蓝色框,它是 frame
的 background color
,其中包括我想放在右上角和第二张图片中的 button
如果我 pack()
按钮...
你会看到会发生什么
1 张图像:
2 图片:
如果你们想帮助我,这是你们需要的必要代码:
from tkinter import *
window = Tk()
# set window title
window.title("Open the Websites")
window.state("zoomed")
# set window background color
window.configure(bg='lightgray')
upFrame = Frame(window, bg='lightgray')
upFrame.grid(row=0, column=0, sticky='nesw')
window.grid_rowconfigure(1, weight = 0)
window.grid_columnconfigure(0, weight = 1)
window.grid_rowconfigure(1, weight = 0)
nw_frame = LabelFrame(upFrame)
nw_frame.pack(anchor='nw')
show_all = Button(nw_frame, text='ΟΛΑ', padx= 10, pady= 10, width= 30)
show_all.pack(side= LEFT)
left_frame = Frame(nw_frame, bg='lightgray')
left_frame.pack(side=LEFT)
midRight_frame = Frame(nw_frame, bg='lightgray')
midRight_frame.pack()
mid_frame = Frame(midRight_frame, bg='lightgray')
mid_frame.pack(side= TOP)
right_frame = Frame(midRight_frame, bg='lightgray')
right_frame.pack(side= BOTTOM)
topleftButton = Button(left_frame, text='<= 20 ΣΤΑΘΕΡΑ', padx= 10, width= 20, activebackground='orange')
topleftButton.pack(side= TOP)
bottomleftButton = Button(left_frame, text='ΣΤΑΘΕΡΑ', padx= 10, width= 20)
bottomleftButton.pack(side= BOTTOM)
topmidButton = Button(mid_frame, text='21 - 100kW', padx= 10, width= 25)
topmidButton.pack(side= LEFT)
bottommidButton = Button(mid_frame, text='> 100kW', padx= 10, width= 20)
bottommidButton.pack(side= RIGHT)
toprightButton = Button(right_frame, text='I-AXIS', padx= 10, width= 25)
toprightButton.pack(side= LEFT)
bottomrightButton = Button(right_frame, text='2-AXIS', padx= 10, width= 20)
bottomrightButton.pack(side= RIGHT)
ne_frame = Frame(upFrame, bg='blue', width= 100, height=10)
ne_frame.pack(anchor= 'ne')
auto_button = Button(ne_frame, text='Αυτόματη Λειτουργία', pady=10)
auto_button.pack(side= RIGHT)
window.mainloop()
您可以在 upFrame
:
的左侧包装 nw_frame
,在右侧包装 ne_frame
...
nw_frame = LabelFrame(upFrame)
nw_frame.pack(side=LEFT, anchor='nw')
...
ne_frame = Frame(upFrame, bg='blue', width= 100, height=10)
ne_frame.pack(side=RIGHT, anchor='ne')
...
如标题所示,我想在屏幕右上角放置一个包含 button
的 frame
...我会给你们两张图片unterstanding,在第一张图片中,您会注意到一个蓝色框,它是 frame
的 background color
,其中包括我想放在右上角和第二张图片中的 button
如果我 pack()
按钮...
1 张图像:
2 图片:
如果你们想帮助我,这是你们需要的必要代码:
from tkinter import *
window = Tk()
# set window title
window.title("Open the Websites")
window.state("zoomed")
# set window background color
window.configure(bg='lightgray')
upFrame = Frame(window, bg='lightgray')
upFrame.grid(row=0, column=0, sticky='nesw')
window.grid_rowconfigure(1, weight = 0)
window.grid_columnconfigure(0, weight = 1)
window.grid_rowconfigure(1, weight = 0)
nw_frame = LabelFrame(upFrame)
nw_frame.pack(anchor='nw')
show_all = Button(nw_frame, text='ΟΛΑ', padx= 10, pady= 10, width= 30)
show_all.pack(side= LEFT)
left_frame = Frame(nw_frame, bg='lightgray')
left_frame.pack(side=LEFT)
midRight_frame = Frame(nw_frame, bg='lightgray')
midRight_frame.pack()
mid_frame = Frame(midRight_frame, bg='lightgray')
mid_frame.pack(side= TOP)
right_frame = Frame(midRight_frame, bg='lightgray')
right_frame.pack(side= BOTTOM)
topleftButton = Button(left_frame, text='<= 20 ΣΤΑΘΕΡΑ', padx= 10, width= 20, activebackground='orange')
topleftButton.pack(side= TOP)
bottomleftButton = Button(left_frame, text='ΣΤΑΘΕΡΑ', padx= 10, width= 20)
bottomleftButton.pack(side= BOTTOM)
topmidButton = Button(mid_frame, text='21 - 100kW', padx= 10, width= 25)
topmidButton.pack(side= LEFT)
bottommidButton = Button(mid_frame, text='> 100kW', padx= 10, width= 20)
bottommidButton.pack(side= RIGHT)
toprightButton = Button(right_frame, text='I-AXIS', padx= 10, width= 25)
toprightButton.pack(side= LEFT)
bottomrightButton = Button(right_frame, text='2-AXIS', padx= 10, width= 20)
bottomrightButton.pack(side= RIGHT)
ne_frame = Frame(upFrame, bg='blue', width= 100, height=10)
ne_frame.pack(anchor= 'ne')
auto_button = Button(ne_frame, text='Αυτόματη Λειτουργία', pady=10)
auto_button.pack(side= RIGHT)
window.mainloop()
您可以在 upFrame
:
nw_frame
,在右侧包装 ne_frame
...
nw_frame = LabelFrame(upFrame)
nw_frame.pack(side=LEFT, anchor='nw')
...
ne_frame = Frame(upFrame, bg='blue', width= 100, height=10)
ne_frame.pack(side=RIGHT, anchor='ne')
...