weixin_43881237 2020-09-08 15:38 采纳率: 0%
浏览 176

运行代码时报错can't invoke "event" command,pycharm中可以正常弹出窗口,点击按钮也可以正常;封装成exe无法执行

class AdminManage:
def init(self, parent_window):
parent_window.destroy()
self.window = Tk() # 初始框的声明
self.window.title('xxx')
self.frame_left_top = tk.Frame(width=300, height=200)
self.frame_right_top = tk.Frame(width=200, height=200)
self.frame_center = tk.Frame(width=600, height=300)
self.frame_bottom = tk.Frame(width=350, height=50)
# 定义下方中心列表区域
self.columns = ("月度", "手续费","销售服务费","总金额")
self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("月度", width=100, anchor='center') # 表示列,不显示
self.tree.column("手续费", width=100, anchor='center')
self.tree.column("销售服务费", width=100, anchor='center') # 表示列,不显示
self.tree.column("总金额", width=100, anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0, column=0, sticky=NSEW)
self.vbar.grid(row=0, column=1, sticky=NS)
self.id = []
self.name = []
self.gender = []
self.age = []
db = cx_Oracle.connect('ta/ta@172.16.5.65:1521/orclta')
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql1 = open('Z:\公共文件夹\wanghn\A-python\9-蚂蚁手续费\当月数据.sql', encoding='UTF-8')#读取初始数据
sql=sql1.read()
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.id.append(row[0])
self.name.append(row[1])
self.gender.append(row[2])
self.age.append(row[3])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!', '数据库连接失败!')
db.close() # 关闭数据库连接
self.tree.insert('', 0, values=(self.id[0], self.name[0],self.gender[0],self.age[0]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col, text=col,
command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
# 定义左上方区域
self.top_title = Label(self.frame_left_top, text="对账月度时间(初始值为当月数据):", font=('Verdana', 12))
self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_id = StringVar() # 声明时间
# 月度时间
self.right_top_id_label = Label(self.frame_left_top, text="月度时间:", font=('Verdana', 15))
self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
self.right_top_id_label.grid(row=1, column=0) # 位置设置
self.right_top_id_entry.grid(row=1, column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
self.right_top_button1 = ttk.Button(self.frame_right_top, text='查询', width=20, command=self.select)
self.right_top_button2 = ttk.Button(self.frame_right_top, text='发送', width=20,command=self.send)
# 位置设置
self.right_top_title.grid(row=1, column=0, pady=10)
self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
# 整体区域定位
self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
self.frame_bottom.grid(row=2, column=0, columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环


  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-09-09 12:21
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器