Python Forum
[Tkinter] GUI Freeze/tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] GUI Freeze/tkinter
#1
Hello Users,

I have a python script called Master which runs continously (using while 1:). Now I want to create a simple GUI using tkinter to Start and Stop the Master script but once started, the GUI does not react and as far as I have read online, this issuse can be solved using Threading. But it seems I am not using the Threading in a correct manner as I am getting Exceptions because of this approach:

Error:
Exception in thread Thread-1: Traceback (most recent call last): File "C:\Program Files\Python27\lib\threading.py", line 801, in __bootstrap_inner self.run()
Will be greatful to your suggestions

My Code Looks as follows:

Master:

def Excecute():
 while 1:
  func1()
  func2()
  # and many other functions 
GUI:


import Tkinter
import tkSimpleDialog
import tkFileDialog
import tkMessageBox
import os
from subprocess import Popen
import sys
import Master as test
import threading


class PST(Tkinter.Tk):
    
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()
        
    
    def initialize(self):

        # Label
        
         self.grid()
         d="Sample Text"
         label1 = Tkinter.Label(self,text="Status :" + self.Status_Text(d),anchor="w").grid(column=0,row=0,columnspan=1,sticky='EW',padx=5,pady=5)        
        
        # Button
         
         button1 = Tkinter.Button(self,text=u"Start",command=self.anfang)
         button1.grid(column=0,row=11,pady=10,padx=10,columnspan=1,sticky='W')
         button2 = Tkinter.Button(self,text=u"Beenden",command=self.beenden)
         button2.grid(column=0,row=11,pady=10,padx=90,sticky='W')
   
    def anfang(self):

        t=threading.Thread(target=test.Execute)
        t.start()

    def Status_Text(self,Meldung):
        
        Text=Meldung
        return (Text)
    
    def beenden(self):
        
        print("Exiting")
        self.destroy()
        sys.exit()
        
        
    
master = CoA_PST(None)
master.title('CoA PST')
w = 300
h = 100
ws = master.winfo_screenwidth() 
hs = master.winfo_screenheight() 
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
master.geometry('%dx%d+%d+%d' % (w, h, x, y))
master.mainloop()
Reply


Messages In This Thread
GUI Freeze/tkinter - by SamGer - Jun-24-2019, 02:10 PM
RE: GUI Freeze/tkinter - by Yoriz - Jun-24-2019, 06:45 PM
RE: GUI Freeze/tkinter - by noisefloor - Jun-24-2019, 07:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Tkinter] Sections of the code causes the GUI to freeze. What should I do? Wilkk 13 3,590 Jan-11-2023, 07:16 PM
Last Post: Wilkk
  [Tkinter] mpv window freeze before video end rfeyer 7 3,445 Feb-20-2021, 09:34 PM
Last Post: rfeyer
  [Tkinter] tkinter freeze DeanAseraf1 0 2,115 Jul-20-2019, 07:46 AM
Last Post: DeanAseraf1
  Tkinter GUI freeze petterg 4 10,925 Jul-01-2019, 03:54 PM
Last Post: petterg

Forum Jump:

User Panel Messages

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