尝试将列表框放置在页面的中间,滚动条位于右侧



我在python中使用了一个带有Tkinter滚动条的列表框。我试图将滚动条放在页面的右侧,如果用户扩展窗口,就允许它扩展,并且将列表框放在窗口的中间,但由于某些原因,列表框只是永久地延伸到页面的右侧和底部,即使它没有扩展这是我的代码,感谢您提前提供的帮助。

from tkinter import *
import tkinter as tk  
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage,Task):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
frame.winfo_toplevel().geometry("1024x720")
frame.configure(bg='#333130')

class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
global listboxz
listboxz = Listbox(self,height='500',width='400')
listboxz.place(x=10, y=120)
scrollbar = Scrollbar(self)
scrollbar.pack(side=RIGHT, fill=Y)
listboxz.configure(yscrollcommand=scrollbar.set)
scrollbar.configure(command=listboxz.yview)
class Task(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
app = SeaofBTCapp()
app.mainloop()

要在页面中间放置place(),需要使用relxrely,如下所示:

listboxz.place(relx=.5, rely=.5, anchor='c')

最新更新