这个 python Tkinter GUI 应用程序通过串行端口与嵌入式 Linux 目标通信。如果应用程序无法使用串行端口连接到目标,是否可以通过 tkMessageBox 通知用户?主机上的 Linux 启动器图标当前用于启动此应用程序,因此如果无法建立连接,则根本不会向用户提供任何反馈。
def initialize(self):
self.ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
...
编辑:这是解决方案
def initialize(self):
try:
self.ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
except:
tkMessageBox.showerror(title="Error", message="No Connection")
sys.exit()