Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically maximized tkinter window

In my project, I am receiving some data occasionally from the serial port and display some data on a Tkinter window depending on the received data. I want to minimize my Tkinter window and perform my normal action on the computer. When any data will be received, the tkinter window should be restored ('un-minimized') and show the result. How can I restore my minized window depending on the received data?

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()

I want to restore my window from the minimized condition when data is received.

like image 714
Akash Nil Avatar asked Oct 19 '22 05:10

Akash Nil


2 Answers

This can be done by invoking the following:

if data == "whatever":   
    window.state('zoomed')
like image 63
turnt Avatar answered Oct 21 '22 22:10

turnt


On receipt of data call:

window.attributes('-zoomed', True)
like image 24
mhawke Avatar answered Oct 21 '22 21:10

mhawke