python - 自动恢复最小化的 tkinter 窗口

标签 python tkinter raspberry-pi

在我的项目中,我偶尔会从串行端口接收一些数据,并根据接收到的数据在 Tkinter 窗口上显示一些数据。我想最小化我的 Tkinter 窗口并在计算机上执行我的正常操作。当接收到任何数据时,tkinter 窗口应该恢复(“未最小化”)并显示结果。如何根据收到的数据恢复我的最小化窗口?

import socket, Tkinter
from Tkinter import *
window = Tk()
window.title("maximize window test")
w, h = window.winfo_screenwidth(),window.winfo_screenheight()
window.geometry("%dx%d+0+0" % (w, h))
window.configure(background="white")
i = servicependingid1 = 1, 0

def monitor():
    s = socket.socket()
    host = socket.gethostname()
    port = 12345
    s.bind((host, port))
    s.listen(5)
    while True:
        global i, servicependingid1
        i = 1
        c, addr = s.accept()
        data = c.recv(1024)
        print data
        if data == "Bid1":
            window.state('zoomed')
            positionr1b1 = Label(window,text="Data comming from  1 ",fg="red",bg="blue",font=("Helvetica", 45))
            positionr1b1.grid(row=i,column=6,sticky=W)
            window.update()
            servicependingid1 = i
            i = i + 1
            c.send("received")
            c.close()
window.after(10, monitor)
window.mainloop()

我想在收到数据时从最小化状态恢复我的窗口。

最佳答案

这可以通过调用以下方法来完成:

if data == "whatever":   
    window.state('zoomed')

关于python - 自动恢复最小化的 tkinter 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31956728/

相关文章:

Python: `from x import *` 没有导入所有内容

python - 如何检测文本中的源代码?

python - 如何处理与坐标的碰撞? (在 python 中)

python - Pygame 动画/事件循环和 Flask-socketio

python - 如何使用 mraa 将 lsm9ds1 连接到 respeaker?

python - 不识别 Python 中的循环变量

python - python 是否将任何没有 cls 或 self 参数的方法隐式视为静态?

python - 如何在 TkInter 中创建平铺布局/流布局?

python - Tkinter Label 没有像我想象的那样工作

linux - 在文本文件中将真正的换行符替换为\n