无法更改列表

时间:2016-07-17 12:03:20

标签: list tkinter radio-button python-3.3

import tkinter as tk   ## most of this is for the Bottoni class
from tkinter import *
import os
import string
import PIL.Image
import PIL.ImageTk
import tkinter.ttk

elenco1 = [elemento1, elemento2, elemento3, elemento4]
elenco2 = [elemento5, elemento6, elemento7, elemento8]
elenco3 = [elemento9, elemento10, elemento11, elemento12]
elenco4 = [elemento13, elemento14, elemento15, elemento16]

BOT = []  ## this is for the Bottoni class
IM = [] ## and this too
elenco = elenco1

class ChangeElenco:

    def __init__ (self):

        def changeElenco(regione):
            if regione == "N":
                self.elenco = elenco1
            elif regione == "K":
                self.elenco = elenco2
            elif regione == "J":
                self.elenco = elenco3
            elif regione == "H":
                self.elenco = elenco4

            elenco = self.elenco

        self.radio1 = Radiobutton(text = '1', value = 1, command = lambda : changeElenco("N")).place (x = 920, y = 150)
        self.radio2 = Radiobutton(text = '2', value = 2, command = lambda : changeElenco("K")).place (x = 920, y = 170)
        self.radio3 = Radiobutton(text = '3', value = 3, command = lambda : changeElenco("J")).place (x = 920, y = 190)
        self.radio4 = Radiobutton(text = '4', value = 4, command = lambda : changeElenco("H")).place (x = 920, y = 210)


class secondWindow:

    def __init__(self):

        self.secondWindow = Tk()
        self.secondWindow.geometry ('500x650+400+30')

class Bottoni:

    def __init__ (stringa, elenco):
        ... 

    def Destroy (self):
        ...

class mainWindow:

    def __init__(self):

        self.mainWindow = Tk()
        self.mainWindow.geometry ('1130x650+100+10')
        self.mainWindow.title('mainWindow')

    def mainEnter (self):

        testoEntry = StringVar()
        testoEntry.set('')
        self.mainEntry = Entry(self.mainWindow, textvariable = testoEntry).place (x = 920, y = 20)


        def search ():
            testoEntry2 = testoEntry.get()
            if testoEntry2 == "":
                pass
            else:
                testoEntry2 = testoEntry2.lower()

            Bottoni.Destroy(self)
            BOT = []

            ChangeElenco() ################ here i need the program to change my list "elenco" when i press a radio button

            Bottoni(testoEntry2, elenco)


        def tracing(a, b, c):
            if len(testoEntry.get()) > 2:
                search()

        testoEntry.trace('w', tracing)

        self.button4Entry = Button (self.mainWindow, text = 'search', command = search).place (x = 1050, y = 17)


MW = mainWindow()
ChangeElenco()
MW.mainEnter()

mainloop()

问题是在这段代码中,我需要ChangeElenco类来改变我的列表,我需要的列表就是我用单选按钮选择的列表,但实际上它只是在该类里面的changeElenco函数内部改变,然后清单仍然是我开头的那个......

0 个答案:

没有答案