|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想引用子窗口root_01 中输出框e_grade,但是在函数tttttttt里面引用不到,求助求助啊
报错:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\panXingxing\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "F:/python/lianxi/treeview.py", line 64, in tttttttt
print(e_grade)
NameError: name 'e_grade' is not defined
代码如下:
import tkinter.ttk
import tkinter
from tkinter import *
from tkinter import ttk
root = tkinter.Tk()
root.geometry('600x300')
mid_one = ['Morning1', 'Morning2', 'Morning3', 'Afternoon1', 'Afternoon2', 'Afternoon3']
mid_two = ['TwoMorning1', 'TwoMorning2', 'TwoMorning3', 'TwoAfternoon1', 'TwoAfternoon2', 'TwoAfternoon3']
mid_three = ['ThreeMorning11', 'ThreeMorning2', 'ThreeMorning3', 'ThreeAfternoon1', 'ThreeAfternoon2',
'ThreeAfternoon3']
def get_combobox_num(key,mid):
combobox_num = 0
print('长度',len(mid))
for i in range(len(mid)):
if key == mid[i]:
print(mid[i])
combobox_num=i
return combobox_num
def offff(*args): #输出选中的树状表里的行内容
values = table.item(table.selection(), 'values')
root_01 = tkinter.Tk()
root_01.geometry('400x200')
e_grade = Entry(root_01, relief=SUNKEN, width=20, ) # 年级输入框
e_grade.insert(0, values[3])
e_grade.pack()
if values[3] == '初一':
print('初一')
combox_class_type = ttk.Combobox(root_01, state='readonly', values=mid_one)
combox_class_type.current(get_combobox_num(values[4],mid_one))
elif values[3] == '初二':
print('初二')
combox_class_type = ttk.Combobox(root_01, state='readonly', values=mid_two)
combox_class_type.current(get_combobox_num(values[4], mid_two))
elif values[3] == '初三':
print('初三')
combox_class_type = ttk.Combobox(root_01, state='readonly', values=mid_three)
combox_class_type.current(get_combobox_num(values[4], mid_three))
combox_class_type.pack()
e_name = Entry(root_01, relief=SUNKEN, width=20, textvariable=values[5]) # 姓名输入框
e_name.insert(0, values[5])
e_name.pack()
e_phone = Entry(root_01, relief=SUNKEN, width=20, textvariable=values[6]) # 电话输入框
e_phone.insert(0, values[6])
e_phone.pack()
e_pay = Entry(root_01, relief=SUNKEN, width=20, textvariable=values[7]) # 缴费输入框
e_pay.insert(0, values[7])
e_pay.pack()
e_remarks = Entry(root_01, relief=SUNKEN, width=20, textvariable=values[9]) # 备注输入框
e_remarks.insert(0, values[9])
e_remarks.pack()
b03 = Button(root_01, text='修改',command=tttttttt)
b03.pack()
root_01.mainloop()
return
def tttttttt():
print(e_grade)
print('fffffff')
return
columns = ['序号', '工作表','行数','年级','课程种类','姓名','电话','缴费','缴费时间','备注', ]
table = tkinter.ttk.Treeview(
master=root, # 父容器
height=10, # 表格显示的行数,height行
columns=columns, # 显示的列
show='headings', # 隐藏首列
)
table.heading(column='序号', text='序号')
table.heading(column='工作表', text='工作表')
table.heading(column='行数', text='行数')
table.heading(column='年级', text='年级')
table.heading(column='课程种类', text='课程种类')
table.heading(column='姓名', text='姓名')
table.heading(column='电话', text='电话')
table.heading(column='缴费', text='缴费')
table.heading(column='缴费时间', text='缴费时间')
table.heading(column='备注', text='备注')
table.column('序号',width=40,anchor='center')
table.column('工作表',width=50,anchor='center')
table.column('行数',width=40,anchor='center')
table.column('年级',width=50,anchor='center')
table.column('课程种类',width=100,anchor='center')
table.column('姓名',width=50,anchor='center')
table.column('电话',width=100,anchor='center')
table.column('缴费',width=40,anchor='center')
table.column('缴费时间',width=80,anchor='center')
table.column('备注',width=100,anchor='center')
neirong = [{'序号': '1' ,
'工作表':'ttttt',
'行数': '66',
'年级': '初三',
'课程种类': 'ThreeAfternoon3',
'姓名': '杜若龙',
'电话': '15865481536',
'缴费': '否',
'缴费时间':'22-5-12',
'备注':'黑师傅拉宋丹妮福利卡脚斗士了咖啡机阿萨德',},
{'序号': '2',
'工作表': 'ttttt',
'行数': '44',
'年级': '初一',
'课程种类': 'Afternoon1',
'姓名': '杜kad',
'电话': '1586548188',
'缴费': '否',
'缴费时间': '22-5-20',
'备注': '黑机阿萨德', }
]
table.insert(parent = "",index='end',values=tuple(neirong[0].values()))
table.insert(parent = "",index='end',values=tuple(neirong[1].values()))
table.bind('<Double-Button-1>',offff)
table.place(x=20,y=10)
root.mainloop() |
|