Automatically restore minimized tkinter window
Asked Answered
B

7

6

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.

Brummett answered 12/8, 2015 at 5:31 Comment(3)
When you say "maximized", do you mean you want it to take up the entire screen, or are you asking how to "un-minimize" it? ie: do you want to force it to fill the screen, or just restore itself to it's previously visible state?Spain
i want to restore it.Brummett
Does this answer your question? tkinter python maximize windowWholesale
H
2

This can be done by invoking the following:

if data == "whatever":   
    window.state('zoomed')
Hod answered 12/8, 2015 at 5:47 Comment(1)
window.state('zoomed') is maximizing my window some time but it missed many time. i am using python 2.7 and windows xp. @ turntBrummett
P
1

On receipt of data call:

window.attributes('-zoomed', True)
Pluck answered 12/8, 2015 at 5:59 Comment(2)
it shows error wrong # args: should be " wm attributes window?-alpha?double?? etc"Brummett
my window is minimized by minimize button of window.want to maximize it on data event@PluckBrummett
S
1

If all you want to do is "un-minimize" the window, call deiconify, which will restore the window to the state it was in before it was minimized.

window.deiconify()
Spain answered 13/8, 2015 at 12:6 Comment(0)
L
0

Just do window.attributes("-fullscreen", True)

Lewse answered 14/5, 2019 at 10:19 Comment(0)
A
0

well there is a very simple fix for the problem

if data == "data":
      window.wm_state('zoomed')
Azoth answered 27/3, 2020 at 15:46 Comment(0)
B
0

I think this is what you are looking for

import tkinter

yourwindow = tkinter.Tk()
yourwindow.state("zoomed")

yourwindow.mainloop()
Boarish answered 28/12, 2020 at 20:26 Comment(0)
L
0

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?

You will never find "Bid1" while raw data is streaming. Because you're setting this if data == "Bid1": and that attribute is boolean. That is wrong.

The correct way to find "Bid1" while raw data is streaming. Use find command, and it will search for "Bid1".

if str(data).find('Bid1') != -1:
    do something
Lillalillard answered 26/10, 2023 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.