弹出一个带有垂直滚动条的列表框

时间:2015-11-18 07:38:51

标签: python tkinter

所以我有以下问题: 我正在使用网格和Toplevel制作一个有垂直滚动条的弹出窗口,事实是滚动条出现在父窗口中(我已经尝试了in_方法,但是没有用)所以我想知道我能做些什么办?

class listbox:
    def __init__(self,master,tamx = 0,tamy = 0,h = 5,pop = True,line = 1,cul = 1,iden = True):

        self.iden = iden #verifies if a 
        self.master = master #window or widget I'm new here
        self.listb = Listbox(master,selectmode = 'browse',width = 15,height = ,font = ('arial','10')) 
        self.listb.grid(in_ = master,row = tamx,column = tamy,columnspan = columna,rowspan = fila) 
        self.pop = pop #to see if a pop up has to appear

        self.scroll = Scrollbar(command = self.listb.yview, orient= VERTICAL) #creates a scrollbar
        self.scroll.grid(in_ = master,row = tamx,column = tamy+1,sticky = 'ns') 
        self.listb.config(yscrollcommand = self.scroll.set)
        if self.pop:
             self.listb.bind("<Double-Button-1>", self.string) 

    def string(self,event):
        value = str((self.listb.get(self.listb.curselection())))
        popUp = pop(value,self.master,self.iden)    


class pop:
    def __init__(self,string,ventana,iden = True):
        if iden: #searching in a list of countries not really the point
        self.country = CodigoIntermedio._encontrar(paises,string) #searches the list for the specific country
        self.words = ['Code','Country','Capital','Surface','Gentilic'] #lists with the words for every characteristic form a country
        toplevel = Toplevel(master = ventana,bg = 'white')


        for x in range(len(self.palabras)): 
            label1 = Label(toplevel, text = self.words[x],bg = 'white') 
            label1.grid(in_ = toplevel,sticky = 'w',row = x)
            label2 = Label(toplevel, text=self.country[x],bg = 'white') 
            label2.grid(in_ = toplevel,sticky = 'w',row = x,column = 1)

            self.box = listbox(toplevel,tamx = 0,tamy = 2, pop = False,fila = 5,columna = 5)
            for x in range(len(self.country[5])): #searches for the words spoken in a country
                 value = CodigoIntermedio.encontrarCodigos(idiomas,self.country[5][x]) 
                 if valor:
                     self.box.listb.insert(END,valor) #los inserta en el listbox

         else: 
             self.language = CodigoIntermedio._encontrar(idiomas,string) 
             self.words = ['Code','Name','Speakers'] 
             toplevel = Toplevel(master = ventana,bg = 'white')


             for x in range(len(self.palabras)): 
                 label1 = Label(toplevel, text = self.words[x],bg = 'white')
                 label1.grid(sticky = 'w',row = x)
                 label2 = Label(toplevel, text=self.language[x],bg = 'white')
                 label2.grid(sticky = 'w',row = x,column = 1)

             self.box = listbox(toplevel,tamx = 0,tamy = 2, pop = False,fila = 3,columna = 3)
             for x in range(len(self.language[3])): 
             valor = CodigoIntermedio.encontrarCodigos(paises,self.idioma[3][x]) 
             if valor:
                 self.box.listb.insert(END,valor)
root = Tk()
root.configure(bg = 'white')
listCountries = listbox(root,tamx = 1, tamy = 0,h = 18)
#paises is a matrix with this structure:
#[[code of a country,name of the country,capital,total residents,gentilic,[list of codes of langauges]]
#CodigoIntermedio.encontrarCodigos searches for a country or a language in the matrix
#idiomas is a mtrix with this structure:
#[[code of the language,name,total speakers,[list of codes of the countries that speak it]]
#i get all the dat from a txt
for x in paises:
    listaCountries.listb.insert(END,x[1])

1 个答案:

答案 0 :(得分:0)

根据您的描述,滚动条的父级是根窗口或根窗口的某个子级。滚动条必须具有父级是顶层,或者是顶层中的其他小部件。