By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

Duplicate widget with threads

P: n/a
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
tu*********@aol.com
http://utilitarian.us - A Guide to Esoteric Technology in Paragon City
http://jarodrussell.livejournal.com/ - Take a guess. ;)
Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.