TKinter problem
C D Wood
justchris84 at hotmail.com
Tue Mar 21 07:03:04 EST 2006
To whom this may concern,
Below is the source code, which
demonstrates a
problem I am having making a GUI for my python project work.
'table.txt'
is a file that is read from the same folder.
My code writes to a text file 'table.txt', and 'table.txt' is displayed
in
the GUI. The user can generate new data at the click of a button
which re-writes 'table.txt', but I can only add the new table to the
GUI
window rather than 'update' the existing one.
Any assistance would be much appreciated,
Regards,
Christian Wood.
Part III Aerospace Engineering
University of Southampton, UK.
##################################################################
from Tkinter import *
#Tkinter User Interface
class MoC:
def __init__(self, master):
frame = Frame(master, width=600, height=800, bd=1)
frame.pack()
#Button frame
iframe4 = Frame(frame, bd=2, relief=SUNKEN)
#Using this button below, I want to update the text box in iframe5.
Button(iframe4, text='Display table.txt',
command=self.DisplayUpdate).pack(side=LEFT, padx=5)
Button(iframe4, text='Quit', command=self.quit).pack(side=LEFT,
padx=5)
iframe4.pack(expand=1, fill=X, pady=10, padx=5)
#Text box frame
iframe5 = Frame(frame, bd=2, relief=SUNKEN)
text=Text(iframe5, height=10, width =70)
fd = open('table.txt') #table.txt must be in the same folder
lines = fd.read()
fd.close()
text.insert(END, lines)
text.pack(side=LEFT, fill=X, padx=5)
sb = Scrollbar(iframe5, orient=VERTICAL, command=text.yview)
sb.pack(side=RIGHT, fill=Y)
text.configure(yscrollcommand=sb.set)
iframe5.pack(expand=1, fill=X, pady=10, padx=5)
#Command definitions
def quit(self):
root.destroy()
def DisplayUpdate(self): #The command definition used to update the
display.
#Could I insert a line here to remove the existing frame/text
box first? <<<<<=====
iframe5 = Frame(root, bd=2, relief=SUNKEN)
text = Text(iframe5, height=10, width =70)
fd = open('table.txt')
lines = fd.read()
fd.close()
text.insert(END, lines)
text.pack(side=LEFT, fill=X, padx=5)
sb = Scrollbar(iframe5, orient=VERTICAL, command=text.yview)
sb.pack(side=RIGHT, fill=Y)
text.configure(yscrollcommand=sb.set)
iframe5.pack(expand=1, fill=X, pady=10, padx=5)
root = Tk()
root.option_add('*font', ('arial', 10))
all = MoC(root)
root.title('2D Method of Characteristics')
root.update
root.mainloop()
More information about the Python-list
mailing list