我在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()
答案 0 :(得分:0)
要使用place()
在页面中间放置内容,您需要使用relx
和rely
,如下所示:
listboxz.place(relx=.5, rely=.5, anchor='c')