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
[EMAIL PROTECTED]
http://utilitarian.us - A Guide to Esoteric Technology in Paragon City
http://jarodrussell.livejournal.com/ - Take a guess. ;)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to