Duplicate widget with threads

A

Andrew Burton

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top