473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

TKinter problem

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

Mar 21 '06 #1
1 2641
ezd
C D Wood wrote:
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()


What you want probably looks like this:

from Tkinter import *
class MoC:
def __init__(self, master):
frame = Frame(master, width=600, height=800, bd=1)
frame.pack()
iframe4 = Frame(frame, bd=2, relief=SUNKEN)
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)
iframe5 = Frame(frame, bd=2, relief=SUNKEN)
self.text=Text(iframe5, height=10, width =70)
# read the file in the update function; create Text & Scrollbar
only once
self.text.pack(side=LEFT, fill=X, padx=5)
sb = Scrollbar(iframe5, orient=VERTICAL,
command=self.text.yview)
sb.pack(side=RIGHT, fill=Y)
self.text.configure(yscrollcommand=sb.set)
iframe5.pack(expand=1, fill=X, pady=10, padx=5)
self.DisplayUpdate()
def _quit(self): # quit is a keyword in python 2.4 IDE
root.destroy()
def DisplayUpdate(self):
fd = open('table.txt')
lines = fd.read()
fd.close()
self.text.config(state=NORMAL)
self.text.delete(1.0, END)
self.text.insert(END, lines)
self.text.config(state=DISABLED)
# previous 4 lines are to make the text READONLY, see more in:
#
http://www.pythonware.com/library/tk...9-patterns.htm
root = Tk()
root.option_add('*font', ('arial', 10))
all = MoC(root)
root.title('2D Method of Characteristics')
root.update
root.mainloop()

ezd

Mar 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
3
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
2
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make....
7
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
2
by: Stewart Midwinter | last post by:
this has me puzzled; I've created a small test app to show the problem I'm having. I want to use subprocess to execute system commands from inside a Tkinter app running under Cygwin. When I...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
1
by: vigacmoe | last post by:
Hi all, I'm trying to write a simple tkinter program, then this problem popped up. The followin code will describe the problem. ------------------------------------------ import Tkinter ...
0
by: wolfonenet | last post by:
Hi All, My setup is: WinXP Python 2.5.1 TKinter version: $Revision: 50704 $ Tcl: 8.4 Debugger: WinPdb
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.