2017-06-20 27 views
-1

我目前正在嘗試使用側滾動條出現在我的Tkinter窗口上的列表框。我無法弄清楚如何使滾動條大小與我的列表框大小相同。繼承人我的代碼:使用Scrolll製作Tkinter列表框

global R3 
global lb 

R3 = Tk() 
gg = "white" 
g = "blue" 
R3.geometry('720x720') 
R3.title(username + " Dropbox") 
R3.resizable(width=False, height=False) 
logoutbt = Button(R3, text="Logout", width=10, height=2, bg=g, fg=gg, font="5", relief=RAISED, overrelief=RIDGE, command=rectologout) 
upload = Button(R3, text="Upload", width=10, height=2, bg=g, fg=gg, font="5", relief=RAISED, overrelief=RIDGE, command=rectoupload) 
logoutbt.place(x=220, y=500) 
upload.place(x=480, y=500) 
button1 = Button(R3, text='Receive file', width=10, height=2, bg=g, fg=gg, font="5", relief=RAISED, overrelief=RIDGE,command = get_file) 

lb = Listbox(R3, height=6,width = 15) 
s.send("RETREIVEA-"+username) 
file_list = s.recv(1024).split("-") 
if file_list == [""]: 
    button1.config(state = DISABLED) 
for file in file_list: 
    lb.insert("end", file) 
yscroll = Scrollbar(R3, orient=VERTICAL) 
lb['yscrollcommand'] = yscroll.set 
yscroll['command'] = lb.yview 
lb.place(x=280,y=200) 
yscroll.place(x=370,y=200) 
button1.place(x=400, y=200) 
R3.mainloop() 

有關如何做到這一點的任何建議?

+0

此代碼不能運行,它有許多缺件。請閱讀如何創建[mcve]。另外,你應該認真考慮_not_使用'place'。對於99.9%的tkinter程序,「grid」和「pack」產生的結果要好得多。 –

回答

0

首先,請閱讀如何創建Minimal, Complete and Verifiable example

您的代碼缺少導入並引用非初始化的對象/變量/函數。

如何實現你想要的?

要麼使用grid代替place或通行高度參數,lb.place(..., height=<whatever you want>)yscroll.place(..., height=<whatever you want>)