我正在编写一些想要与我的团队共享的脚本,因此我一直在构建一堆日志记录,以便在他们在某个地方遇到崩溃时更容易进行调试,从那时起我就可以看到到底发生了什么崩溃。
一般记录到文件没有问题,但我有一个未捕获的异常问题。我尝试了各种方法来使其正常工作,例如参见this和this。当我从 IDLE 或命令提示符运行它时,似乎 sys.excepthook 没有被调用。
昨天,如果异常发生在主模块中,它会正确记录,但如果异常发生在导入的类中,则不会正确记录。现在异常根本不会被记录,我不知道我改变了什么(所以我今天安装了 Git :-P)
这是我试图开始工作的代码,即主模块:
import tkinter as tk
import sys
import traceback
import logging
import datetime
import exception_logging_test_imported_class as impclass
# Main Class
class ExceptMain(tk.Frame):
def __init__(self, parent):
logging.info('Start main')
tk.Frame.__init__(self, parent, relief='groove', bd=4)
self.parent = parent
self.pack()
tk.Label(self, text='This is the main class', bg='white').pack()
tk.Button(self, text='Start subframe', command=self.run).pack()
tk.Button(self, text='Throw main exception', command=self.throwex).pack()
tk.Button(self, text='Start imported class', command=self.start_import).pack()
# Function to start another frame, from this same file
def …Run Code Online (Sandbox Code Playgroud) 我一定遗漏了一些明显的东西,我的 Tkinter 程序中有两个框架,每个框架在网格布局中都有一堆标签。我想将鼠标点击绑定到其中一个而不是另一个。我目前使用
root.bind("<Button-1>", mouse_function)
Run Code Online (Sandbox Code Playgroud)
但如果我点击另一个框架,这也会触发。我假设使用
schedule_frame.bind("<Button-1>", mouse_function)
Run Code Online (Sandbox Code Playgroud)
会工作,但后来我在任何地方都没有得到回应。
我调用的函数是:
def mouse_function(event):
y = event.widget.grid_info()['row']
x = event.widget.grid_info()['column']
widgets[(y, x)].configure(state="active")
shiftSelection(y,x)
Run Code Online (Sandbox Code Playgroud)