Duplicate widget with threads

Andrew Burton tuglyraisin at aol.com
Sun Jun 8 04:16:16 CEST 2008


I'm trying to create a GUI application with CherryPy running in the 
background for communications.  However, when I use Tkinter, CherryPy, 
and thread together in a test script, my Tkinter widget pops up twice. 
Could someone tell me what I'm doing wrong?  Thanks!  Here's the code:

--- START CODE BLOCK ---

import cherrypy, threading

from Tkinter import *

theVar = "Hello, World"

class App:
     def __init__ (self, master):
         self.master = master

         self.str = Entry(master)
         self.str.grid(row=0, column=0)

         self.button1 = Button(master, text="New string", 
command=self.newString)
         self.button1.grid(row=0, column=1)

     def newString(self):
         global theVar
         theVar = self.str.get()

class HelloWorld:
     def index(self):
         global theVar
         return theVar
     index.exposed = True

class TkThread ( threading.Thread ):
     def run (self):
         root = Tk()
         app = App(root)
         root.mainloop()

class CpThread ( threading.Thread ):
     def run (self):
         cherrypy.root = HelloWorld()
         cherrypy.server.start()

CpThread().start()
TkThread().start()

--- STOP CODE BLOCK ---

-- 
Andrew Burton
tuglyraisin at aol.com
http://utilitarian.us - A Guide to Esoteric Technology in Paragon City
http://jarodrussell.livejournal.com/ - Take a guess. ;)



More information about the Python-list mailing list