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() 1 2600
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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
...
|
by: wolfonenet |
last post by:
Hi All,
My setup is:
WinXP
Python 2.5.1
TKinter version: $Revision: 50704 $
Tcl: 8.4
Debugger: WinPdb
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |