Python Forum
Exiting/killing a program with tkinter but leaving the graphic on the screen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exiting/killing a program with tkinter but leaving the graphic on the screen
#1
I want the opposite of what most people want. I call a python subprogram to put a tk label on the screen. I want that program to terminate itself when it outputs the label (best) or to be sent a "kill" signal from the parent that will terminate the program but leave the label on the screen. Is that possible?

Note that the label is not interactive (i.e. not a button or anything that returns a value).

Note that the label will not have any titlebar. ".overrideredirect(1)"
Reply
#2
For me, if there is a label on the screen, or any image, it means that there is a running program that displays this image. Do you want te replace the python process by some other program?
Reply
#3
Something like this?
In this example I use just the stdout of the subprogramm, to set the label.
For demonstration, it's called after 5s.

gui.py
import sys
from tkinter import Tk, Button, Variable
from subprocess import check_output
from threading import Timer


def make_gui():
    root = Tk()
    text = Variable(root)
    text.set('Before')
    Button(root, textvariable=text).pack()
    Button(root, text='Exit', command=root.destroy).pack()
    return root, text


def main():
    root, text_var = make_gui()
    # with threadnig timer
    #timer = Timer(5, label, args=(text_var,))
    #timer.start()

    # root.after
    root.after(5000, label, text_var)
    root.mainloop()


def label(text_var):
    stdout = check_output([sys.executable, 'subprogram.py'], encoding='utf8')
    text_var.set(stdout)


if __name__ == '__main__':
    sys.exit(main())
subprogram.py
#!/usr/bin/env python3

print('Hello Label')
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
DeaD_EyE,

No. I would want a python program like your button program (but I don't need active buttons) that when it was executed by another script, it would output the "Button" (or in my case a "label" then it would terminate or be terminated but leave the "button" (in my case, jut a label) behind even though the program that produced it is gone. Think of a program like xsetbg. If my python program called it as a subprocess, it would set the background then terminate but the background would not be "unset". Now, I don't want to set a background. I just want to create a label (with text or images or both or ..) then exit leaving that label sitting on the screen.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Graphic Interface with Tkinter IgnacioMora23 0 1,761 May-27-2021, 04:35 AM
Last Post: IgnacioMora23
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 5,232 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 10,606 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  Library for graphic Gantt chart Aregmax 1 4,400 Apr-19-2019, 06:41 PM
Last Post: Larz60+
  [Tkinter] Unable to Obtain values from one Tkinter Program into another nilaybnrj 1 2,535 Aug-24-2018, 01:24 PM
Last Post: Gribouillis
  Tkinter touch screen button click ashtona 2 9,577 Apr-13-2018, 11:46 AM
Last Post: buran
  Want to see sample graphic output for python omar 3 2,941 Dec-22-2017, 08:12 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020