使用按钮(envoi)我打开一个新窗口并在数组中写入元素的值(选择)。在我关闭这个窗口并调用一个函数(window2)之后。我想在这个函数中读取选项如果我写 printchoices.get(),我有一个错误:全局名称 'choices' 没有定义
# -*- coding: utf-8 -*-
from Tkinter import *
root = Tk()
group = LabelFrame(root, text=" 1. Paramètrage: ")
group.grid(row=0, columnspan=5, sticky='W', \
padx=5, pady=5, ipadx=5, ipady=5)
dropVar2=StringVar()
dropVar2.set("----")
opt3 = OptionMenu(group, dropVar2, '----', 'Pondéraux', 'Atomiques')
opt3.grid(row=4, column=1, columnspan=7, sticky='WE', padx=5, pady=2)
def state():
if dropVar2.get()=='Atomiques':
winE=Toplevel(root)
group = LabelFrame(winE, text="Pourcentages atomiques", padx=5,pady=5)
group.pack(padx=25, pady=25)
entries = []
j = 0
choices = ['C', 'Ni', 'Co', 'Fe', 'Cr', 'Al', 'Ti', 'Ta', 'Nb',
'Hf', 'V', 'Re', 'Mo', 'W', 'B', 'Zr', 'Mg', 'Y']
while j < len(choices) :
valeurOneLabel = Label(group, text=choices[j])
valeurOneLabel.grid(row=j+1, column=0, columnspan=1, sticky='WE', padx=5, pady=2)
en = Entry(group, text="")
en.grid(row=j+1, column=1)
entries.append(en)
j+=1
for s in range(len(choices)):
choices[s] = entries[s]
exitButton = Button(winE, text = 'Close', command = lambda: window2(winE)).pack()
def window2(winE):
winA=Toplevel(root)
winA.geometry('400x600+600+50')
print choices.get()
winE.destroy()
Button(group, text='envoi', command = state).grid(row=5, column=0)
root.geometry("450x350+100+100")
root.title("Développement d'alliages")
root.mainloop()