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(r ow=0, column=0)
self.button1 = Button(master, text="New string",
command=self.ne wString)
self.button1.gr id(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.Threa d ):
def run (self):
root = Tk()
app = App(root)
root.mainloop()
class CpThread ( threading.Threa d ):
def run (self):
cherrypy.root = HelloWorld()
cherrypy.server .start()
CpThread().star t()
TkThread().star t()
--- STOP CODE BLOCK ---
--
Andrew Burton
tuglyraisin@aol .com
http://utilitarian.us - A Guide to Esoteric Technology in Paragon City
http://jarodrussell.livejournal.com/ - Take a guess. ;)
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(r ow=0, column=0)
self.button1 = Button(master, text="New string",
command=self.ne wString)
self.button1.gr id(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.Threa d ):
def run (self):
root = Tk()
app = App(root)
root.mainloop()
class CpThread ( threading.Threa d ):
def run (self):
cherrypy.root = HelloWorld()
cherrypy.server .start()
CpThread().star t()
TkThread().star t()
--- STOP CODE BLOCK ---
--
Andrew Burton
tuglyraisin@aol .com
http://utilitarian.us - A Guide to Esoteric Technology in Paragon City
http://jarodrussell.livejournal.com/ - Take a guess. ;)