我的GUI程序遇到了一些问题,滚动条就在底部最后一帧的右侧,我已经尝试了很多东西而没有解决我的问题,我只想把滚动条放在上面所有帧的底部。
这是代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#spyder
from Tkinter import *
import tkFileDialog
def curdir():
cdir = tkFileDialog.askdirectory(parent=finestra, initialdir="/home")
v.set(cdir)
#MAIN
finestra = Tk()
finestra.title("Creacio de fitxer comprimit")
f=Frame(finestra)
b=Button(f,text='Escollir directori treball',command=curdir)
b.pack(side=LEFT)
v=StringVar()
v.set("/home")
e1=Entry(f,width=35,textvariable=v)
e1.pack(side=LEFT)
l1=Label(f,text="Fitxers a incorporar al fitxer tar:")
l1.pack(side=TOP,anchor=N,padx=90)
f.pack(side=TOP)
f1=Frame(finestra)
f1.pack(side=LEFT,anchor=NW)
l2=Label(f1,text="Llista:")
l2.pack(side=LEFT)
br=Button(f1,text='Reomplir')
br.pack(side=LEFT)
bo=Button(f1,text='Ocultar no seleccionats')
bo.pack(side=LEFT)
bos=Button(f1,text='Ocultar seleccionats')
bos.pack(side=LEFT)
Label(f1,text="\t\tCompresió").pack(side=LEFT)
rb1=Radiobutton(f1,text="cap").pack(side=LEFT)
rb2=Radiobutton(f1,text="gzip",value="gzip").pack(side=LEFT)
rb3=Radiobutton(f1,text="bzip2",value="bzip2").pack(side=LEFT)
rb4=Radiobutton(f1,text="xz",value="xz").pack(side=LEFT)
f2=Frame(finestra)
f2.pack(side=RIGHT,fill="both")
scrollbar = Scrollbar(f2)
scrollbar.pack(side=RIGHT, fill=Y)
listbox = Listbox(f2, bd=0, yscrollcommand=scrollbar.set)
listbox.pack(side=LEFT)
scrollbar.config(command=listbox.yview)
mainloop( )
答案 0 :(得分:0)
最后将框架f侧选项更改为TOP,似乎当你把东西放到TOP时,剩下的东西都会落到这一个,这就是我不理解的,我让最后的代码也许有人会对tkinter帧位置产生同样的问题。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#spyder
from Tkinter import *
import tkFileDialog
def curdir():
cdir = tkFileDialog.askdirectory(parent=finestra, initialdir="/home")
v.set(cdir)
#MAIN
finestra = Tk()
finestra.title("Creacio de fitxer comprimit")
f=Frame(finestra)
f.pack(side=TOP)
b=Button(f,text='Escollir directori treball',command=curdir)
b.pack(side=LEFT,anchor=W)
v=StringVar()
v.set("/home")
e1=Entry(f,width=35,textvariable=v)
e1.pack(side=LEFT)
l1=Label(f,text="Fitxers a incorporar al fitxer tar:")
l1.pack(side=TOP,anchor=N,padx=90)
f1=Frame(finestra)
f1.pack(side=TOP,anchor=NW)
l2=Label(f1,text="Llista:")
l2.pack(side=LEFT)
br=Button(f1,text='Reomplir')
br.pack(side=LEFT)
bo=Button(f1,text='Ocultar no seleccionats')
bo.pack(side=LEFT)
bos=Button(f1,text='Ocultar seleccionats')
bos.pack(side=LEFT)
Label(f1,text="\t\tCompresió").pack(side=LEFT)
rb1=Radiobutton(f1,text="cap").pack(side=LEFT)
rb2=Radiobutton(f1,text="gzip",value="gzip").pack(side=LEFT)
rb3=Radiobutton(f1,text="bzip2",value="bzip2").pack(side=LEFT)
rb4=Radiobutton(f1,text="xz",value="xz").pack(side=LEFT)
f2=Frame(finestra)
f2.pack(side=LEFT,anchor=W)
f3=Frame(finestra)
f3.pack(side=LEFT)
Label(f3,text="Tots:").pack(side=TOP)
tots=Button(f3,text=">>>").pack(side=TOP)
Label(f3,text="Als seleccionats:").pack(side=TOP)
af=Button(f3,text="-->").pack(side=TOP)
qt=Button(f3,text="<--").pack(side=TOP)
Label(f3,text="Tots:").pack(side=TOP)
cap=Button(f3,text="<<<").pack(side=TOP)
scrollbar = Scrollbar(f2)
scrollbar.pack(side=RIGHT, fill=Y)
listbox = Listbox(f2, bd=0, yscrollcommand=scrollbar.set,width=55)
listbox.pack(side=LEFT)
scrollbar.config(command=listbox.yview)
mainloop( )