【发布时间】:2020-12-26 13:50:28
【问题描述】:
我有一个简单的图形程序,它在远程树莓的触摸屏上显示一些指令和触摸按钮。
我没有直接执行,而是通过 SSH 连接运行它,所以我的桌面应用程序日志中有。
我想在运行脚本的控制台中进行一些简短的交互,例如执行某些函数或更改某些变量的值。
这可能吗?
我不想在 TKinter 窗口中创建控制台,正如 alessandro 所问的: How to embed a terminal in a Tkinter application?
不确定我是否应该使用简短的子进程,如 user1941008,但 htis 似乎太复杂了 Write to terminal in Tkinter GUI
我不喜欢为这个东西创建客户端/服务器设置或中间缓冲区,太复杂了,我必须重写东西才能将日志发送到新程序。
我添加了我的代码的一个小版本:
#!/usr/bin/env python3
import tkinter as tk
class _tkapp(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.redButton = tk.Button(self, text='Make me red', command=self.paintMeRed)
self.redButton.pack(side='top')
self.blueButton = tk.Button(self, text='Make me blue', command=self.paintMeBlue)
self.blueButton.pack(side='top')
self.quit = tk.Button(self, text='QUIT', fg='red', command=self.master.destroy)
self.quit.pack(side='bottom')
def paintMeRed(self):
tk_root.configure(background='red')
print('user click on RED')
def paintMeBlue(self):
tk_root.configure(background='blue')
print('user click on BLUE')
tk_root = tk.Tk()
tk_root.geometry("200x120")
tk_app = _tkapp(master=tk_root)
tk_app.mainloop()
这让我可以在控制台上看到用户点击了什么, 我的目标,也可以从控制台更改颜色
【问题讨论】:
-
您可以使用信号与正在运行的应用程序进行交互。
标签: python python-3.x tkinter tkinter-canvas