To whom this may concern,
Attatched is the source code, which demonstrates a
problem I am having making a GUI for my python project  work. Both
files need to be in 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.
"""
Program to send to Python Tutors.
##########################################################################
Question: How do I simply update a table from within TKinter?, this
current program just adds the new text box, so is there a way of removing
the old one first?, or do I have to try a completely different approach?

I am completely new to TKinter, and GUI programming, my background is just
solving numerical problems using Numeric and math and pylab.
##########################################################################
Christian Wood, 2006 for Part III Individual Project, [EMAIL PROTECTED]
(Last modified: Wood 16/03/1006)
"""
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()
Results Table - Mexit=3.00, 10 waves, gamma=1.40

Isentropic area ratio=4.234568, MoC area ratio=4.223553
Difference between the area ratios=0.011015

node       K-      K+      Theta       Nu      M       Mu          x        y
    1    0.00     0.00     0.00     0.00     1.00    88.94     0.01     0.00
    2    5.53     0.00     2.76     2.76     1.17    58.99     0.30     0.55
    3   11.06     0.00     5.53     5.53     1.28    51.58     0.35     0.63
    4   16.59     0.00     8.29     8.29     1.38    46.62     0.39     0.69
    5   22.11     0.00    11.06    11.06     1.47    42.82     0.43     0.74
    6   27.64     0.00    13.82    13.82     1.56    39.72     0.46     0.78
    7   33.17     0.00    16.59    16.59     1.66    37.08     0.49     0.82
    8   38.70     0.00    19.35    19.35     1.75    34.79     0.52     0.86
    9   44.23     0.00    22.11    22.11     1.85    32.75     0.54     0.90
   10   49.76     0.00    24.88    24.88     1.95    30.92     0.57     0.94
   11   49.76     0.00    24.88    24.88     1.95    30.92     0.90     1.42
   12    5.53    -5.53     0.00     5.53     1.28    51.58     0.70     0.00
   13   11.06    -5.53     2.76     8.29     1.38    46.62     0.83     0.16
   14   16.59    -5.53     5.53    11.06     1.47    42.82     0.93     0.27
   15   22.11    -5.53     8.29    13.82     1.56    39.72     1.02     0.37
   16   27.64    -5.53    11.06    16.59     1.66    37.08     1.10     0.46
   17   33.17    -5.53    13.82    19.35     1.75    34.79     1.18     0.55
   18   38.70    -5.53    16.59    22.11     1.85    32.75     1.26     0.65
   19   44.23    -5.53    19.35    24.88     1.95    30.92     1.34     0.74
   20   49.76    -5.53    22.11    27.64     2.05    29.26     1.43     0.84
   21   49.76    -5.53    22.11    27.64     2.05    29.26     2.41     2.07
   22   11.06   -11.06     0.00    11.06     1.47    42.82     1.00     0.00
   23   16.59   -11.06     2.76    13.82     1.56    39.72     1.13     0.12
   24   22.11   -11.06     5.53    16.59     1.66    37.08     1.25     0.23
   25   27.64   -11.06     8.29    19.35     1.75    34.79     1.36     0.34
   26   33.17   -11.06    11.06    22.11     1.85    32.75     1.47     0.44
   27   38.70   -11.06    13.82    24.88     1.95    30.92     1.58     0.55
   28   44.23   -11.06    16.59    27.64     2.05    29.26     1.70     0.66
   29   49.76   -11.06    19.35    30.41     2.15    27.73     1.81     0.79
   30   49.76   -11.06    19.35    30.41     2.15    27.73     3.34     2.42
   31   16.59   -16.59     0.00    16.59     1.66    37.08     1.29     0.00
   32   22.11   -16.59     2.76    19.35     1.75    34.79     1.44     0.11
   33   27.64   -16.59     5.53    22.11     1.85    32.75     1.58     0.22
   34   33.17   -16.59     8.29    24.88     1.95    30.92     1.72     0.34
   35   38.70   -16.59    11.06    27.64     2.05    29.26     1.87     0.46
   36   44.23   -16.59    13.82    30.41     2.15    27.73     2.02     0.59
   37   49.76   -16.59    16.59    33.17     2.26    26.31     2.17     0.73
   38   49.76   -16.59    16.59    33.17     2.26    26.31     4.35     2.75
   39   22.11   -22.11     0.00    22.11     1.85    32.75     1.62     0.00
   40   27.64   -22.11     2.76    24.88     1.95    30.92     1.79     0.11
   41   33.17   -22.11     5.53    27.64     2.05    29.26     1.97     0.23
   42   38.70   -22.11     8.29    30.41     2.15    27.73     2.15     0.36
   43   44.23   -22.11    11.06    33.17     2.26    26.31     2.34     0.51
   44   49.76   -22.11    13.82    35.94     2.37    24.99     2.54     0.66
   45   49.76   -22.11    13.82    35.94     2.37    24.99     5.54     3.08
   46   27.64   -27.64     0.00    27.64     2.05    29.26     2.00     0.00
   47   33.17   -27.64     2.76    30.41     2.15    27.73     2.21     0.12
   48   38.70   -27.64     5.53    33.17     2.26    26.31     2.44     0.26
   49   44.23   -27.64     8.29    35.94     2.37    24.99     2.67     0.41
   50   49.76   -27.64    11.06    38.70     2.48    23.76     2.93     0.58
   51   49.76   -27.64    11.06    38.70     2.48    23.76     6.97     3.39
   52   33.17   -33.17     0.00    33.17     2.26    26.31     2.47     0.00
   53   38.70   -33.17     2.76    35.94     2.37    24.99     2.74     0.14
   54   44.23   -33.17     5.53    38.70     2.48    23.76     3.03     0.30
   55   49.76   -33.17     8.29    41.46     2.60    22.60     3.35     0.48
   56   49.76   -33.17     8.29    41.46     2.60    22.60     8.71     3.69
   57   38.70   -38.70     0.00    38.70     2.48    23.76     3.07     0.00
   58   44.23   -38.70     2.76    41.46     2.60    22.60     3.42     0.16
   59   49.76   -38.70     5.53    44.23     2.73    21.50     3.81     0.35
   60   49.76   -38.70     5.53    44.23     2.73    21.50    10.86     3.95
   61   44.23   -44.23     0.00    44.23     2.73    21.50     3.85     0.00
   62   49.76   -44.23     2.76    46.99     2.86    20.46     4.33     0.20
   63   49.76   -44.23     2.76    46.99     2.86    20.46    13.53     4.14
   64   49.76   -49.76     0.00    49.76     3.00    19.47     4.92     0.00
   65   49.76   -49.76     0.00    49.76     3.00    19.47    16.86     4.22
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to