Global Variables + Threads

Adonis deltapigz at telocity.com
Tue Jun 12 16:19:54 EDT 2001


in python im declaring varibles in which willbe used by Tkinter as
objects within itself; now since they are globally declared i assumed
they would be fill as soon as the class thread finishes execution. or by
being a thread; thus being pushed to its own thread makes it lose
"contact" with the global variable and instead declares it as local?

if this is the case then how may i fix it?

thanks in advance,

Adonis




--begin code--

from Tkinter import *
from threading import Thread
import sys

root = Tk()

b = 0
e = 0
t = 0
frame = 0

class pshgui(Thread):
    def __init__(self):
        Thread.__init__(self)

    def run(self):
        frame = Frame(root, width=200, height=15)
        frame.grid(row=0, column=0)

        # creating textbox field
        t = Text(frame, width=50, height=10, fg="darkblue")
        t.grid(row=1, column=0)

        # setting color tags to use inthe text box
        t.tag_config("ver", foreground="blue", justify=CENTER)
        t.tag_config("err", foreground="red")


        # entry box
        e = Text(frame, width=26, height=1, fg="darkblue")
        e.grid(row=0, column=0, sticky=W)

        # create a button
        b = Button(frame, text="connect", width=6, height=1,
command=frame.quit)
        b.grid(row=0, column=0, sticky=E)

        # inserting program version+platform running
        t.insert(END, "Py 01.1/" + sys.platform + "\n\n","ver")

gui = pshgui()
gui.start()
root.mainloop()




More information about the Python-list mailing list