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
#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


Messages In This Thread
RE: Exiting/killing a program with tkinter but leaving the graphic on the screen - by DeaD_EyE - Apr-07-2019, 12:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Graphic Interface with Tkinter IgnacioMora23 0 1,823 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,385 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 11,071 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  Library for graphic Gantt chart Aregmax 1 4,531 Apr-19-2019, 06:41 PM
Last Post: Larz60+
  [Tkinter] Unable to Obtain values from one Tkinter Program into another nilaybnrj 1 2,608 Aug-24-2018, 01:24 PM
Last Post: Gribouillis
  Tkinter touch screen button click ashtona 2 9,725 Apr-13-2018, 11:46 AM
Last Post: buran
  Want to see sample graphic output for python omar 3 3,029 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