<div> </div>
<div>  This sounds like a great use for **the canvas widget.**</div>
<div>  1.  Draw layout with canvas lines and rectangles.<br>  2.  Draw text representing sensor readings onto canvas.<br>  3.  Refresh display by reconfiguring text, once a second.</div>
<div><br>  The great thing about canvas is that -- once you&#39;ve got<br>  text placed on it, you can just alter the text via the<br>  canvas.itemconfigure method.</div>
<div><br>  Here&#39;s a rendering of your program:</div>
<div>------------------------------------------------------------------------</div>
<div>from tkinter import *</div>
<div><br>class BasicCanvasFrame1(Canvas):</div>
<div>    &quot;&quot;&quot;Basic canvas frame.</div>
<div>    (Strictly, NOT a Frame -- but we&#39;re using it sort of like one.)</div>
<div>    For convenience, there is a size parameter offering typical sizes:<br>      320x200   &quot;CGA&quot;<br>      640x480   &quot;VGA&quot;<br>      1024x768  &quot;XGA&quot;<br>      1280x1024 &quot;SVGA&quot;<br>
                &quot;FULL&quot;  -- full screen mode</div>
<div>    For organizing&#39;s sake, the BasicCanvasFrame suggests a function,<br>    &quot;draw,&quot; for drawing onto it with.</div>
<div>    Also, there are some common event registrations, so that you do not<br>    need to register them yourself:<br>    * mouse clicks,<br>    * mouse motion,<br>    * key presses<br>    &quot;&quot;&quot;</div>
<div>    def __init__(self, title=&quot;Untitled Frame&quot;,<br>                 size=&quot;VGA&quot;, width=None, height=None,<br>                 enable_per_second=False,<br>                 master=None,<br>                 external_delegate=None):<br>
        self.external_delegate = external_delegate<br>        # 1. Initialize Frame<br>        size = size.upper()<br>        if size != &quot;FULL&quot;:<br>            if width is None:<br>                width = {&quot;CGA&quot;: 320, &quot;VGA&quot;: 640,<br>
                         &quot;XGA&quot;: 1024, &quot;SVGA&quot;: 1280}[size]<br>            if height is None:<br>                height = {&quot;CGA&quot;: 200, &quot;VGA&quot;: 480,<br>                          &quot;XGA&quot;: 768, &quot;SVGA&quot;: 1024}[size]<br>
            Canvas.__init__(self, master, width=width, height=height)<br>            self.master.title(title)<br>        else:<br>            Canvas.__init__(self, master)<br>            (width, height) = tk_fullscreen(self)<br>
            self.configure(width=width, height=height)<br>        self.pack(anchor=N+W, fill=&#39;both&#39;, expand=&#39;yes&#39;)</div>
<div>        # Fix origin displayer, per:<br>        #   <a href="http://tkinter.unpythonic.net/wiki/Widgets/Canvas?highlight=(canvas">http://tkinter.unpythonic.net/wiki/Widgets/Canvas?highlight=(canvas</a>)<br>        self.xview_moveto(0)<br>
        self.yview_moveto(0)</div>
<div>        # 2. Bind<br>        self.bind(&quot;&lt;Button-1&gt;&quot;, self.left_click)<br>        self.bind(&quot;&lt;Button-3&gt;&quot;, self.right_click)<br>        #self.bind(&quot;&lt;Any-KeyPress&gt;&quot;, self.keypress)<br>
        self.bind_all(&#39;&lt;Key&gt;&#39;, self.keypress)<br>        self.bind_all(&#39;&lt;Key-Alt_L&gt;&#39;, self.keypress)<br>        self.bind_all(&#39;&lt;Key-Alt_R&gt;&#39;, self.keypress)<br>#        self.bind_all(&#39;&lt;Key-&gt;&#39;, self.keypress)<br>
        self.bind(&quot;&lt;Motion&gt;&quot;, self.motion)</div>
<div>        # 3. Draw<br>        self.wait_visibility()<br>        self.draw()<br>        if external_delegate is not None:<br>            external_delegate.draw(self)</div>
<div>        # 4. Turn on per-second events, if requested<br>        if enable_per_second:<br>            self.after(1000, self._per_second)</div>
<div>    def _per_second(self):<br>        self.per_second()<br>        self.after(1000, self._per_second)</div>
<div>    def draw(self):<br>        pass</div>
<div>    def left_click(self, evt):<br>        pass</div>
<div>    def right_click(self, evt):<br>        pass</div>
<div>    def keypress(self, evt):<br>        &quot;&quot;&quot;Key pressed.</div>
<div>        evt.keysym  -- super-friendly key symbol<br>        evt.char  -- For textual characters, this is the char.<br>        evt.keycode  -- For recognizing things like...<br>        &quot;&quot;&quot;<br>        pass</div>

<div>    def motion(self, evt):<br>        pass</div>
<div>    def per_second(self):<br>        pass</div>
<div><br>class MickSulleysTemperatureSensor(BasicCanvasFrame1):<br>    <br>    def __init__(self, **args):<br>        BasicCanvasFrame1.__init__(<br>            self,<br>            title=&quot;Mike Sulley&#39;s Temperature Sensor&quot;,<br>
            width=130*3,<br>            height=75*3,<br>            enable_per_second=True)<br>    <br>    def draw(self):<br>        self.create_rectangle(45*3,35*3,85*3,55*3, outline=&quot;blue&quot;)<br>        for (x1,y1,x2,y2) in [(15*3,15*3, 55*3,15*3),<br>
                              (55*3,15*3, 55*3,35*3),<br>                              (15*3,45*3, 45*3,45*3),<br>                              (85*3,45*3,105*3,45*3)]:<br>            self.create_line(x1,y1,x2,y2)<br>        self.temperature_item = {}<br>
        for (x,y,name) in [( 15*3,15*3, &quot;A&quot;),<br>                           ( 55*3,35*3, &quot;B&quot;),<br>                           ( 15*3,45*3, &quot;C&quot;),<br>                           ( 45*3,45*3, &quot;D&quot;),<br>
                           ( 85*3,45*3, &quot;E&quot;),<br>                           (105*3,45*3, &quot;F&quot;)]:<br>            text_item = self.create_text(x+5,y+2, text=&quot;&lt;&quot;+name+&quot;&gt;&quot;,<br>                                         anchor=NW)<br>
            self.temperature_item[name] = text_item<br>    <br>    def get_temperature(self, sensor_name):<br>        &quot;&quot;&quot;Put your code in here.&quot;&quot;&quot;<br>        import random<br>        return random.randint(72,95)<br>
    <br>    def per_second(self):<br>        for (sensor_name, text_item) in self.temperature_item.items():<br>            cur_temperature = self.get_temperature(sensor_name)<br>            self.itemconfigure(text_item,<br>
                               text=&quot;%s: %d&quot; % (sensor_name,<br>                                                cur_temperature))</div>
<div>MickSulleysTemperatureSensor().mainloop()</div>
<div>------------------------------------------------------------------------</div>
<div><br>  (This is longer than is strictly necessary; I&#39;m reusing<br>   BasicCanvasFrame1 from my notes to make this quickly.)</div>
<div>  The main points of interest are:</div>
<div>  * MickSulleysTemperatureSensor.draw:<br>    (the drawing code)</div>
<div>  * MickSulleysTemperatureSensor.per_second:<br>    (the itemconfigure line)</div>
<div>  * BasicCanvasFrame1.__init__:<br>    (Canvas initialization, packing code, Canvas.after<br>    initialization)</div>
<div>  * BasicCanvasFrame1._per_second:<br>    (Canvas.after continuity)</div>
<div><br>  Feel free to adapt and reuse the code here.</div>
<div>  (If you experiment with Canvas, I might suggest using<br>   BasicCanvasFrame1 yourself -- it has made my own<br>   experimentation a lot easier.)</div>
<div> </div>
<div>  Sincerely,</div>
<div>    Lion Kimbro</div>
<div> </div>
<div> </div>
<div class="gmail_quote">On Mon, Oct 19, 2009 at 8:29 AM, MickSulley <span dir="ltr">&lt;<a href="mailto:mick@sulley.info">mick@sulley.info</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote"><br>Hi,<br><br>I am new to TKinter and struggling somewhat.<br><br>I have a Python program that reads a number of temperatures from sensors in<br>
tanks and pipework, that is working fine.  I now want to display those<br>temperatures, ideally a simple diagram of the pipework with boxes displaying<br>the values.  I don&#39;t need any user input, it just runs forever once started<br>
<br>My initial thought was to use a text widget for the whole page and update<br>the areas that show the values.<br><br>Is that the best way to do it?  Can anyone give me some pointers on<br>constructing the program?<br><br>
Thanks<br><br>Mick<br><font color="#888888">--<br>View this message in context: <a href="http://www.nabble.com/Newbie-question---displaying-data-tp25960335p25960335.html" target="_blank">http://www.nabble.com/Newbie-question---displaying-data-tp25960335p25960335.html</a><br>
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.<br><br>_______________________________________________<br>Tkinter-discuss mailing list<br><a href="mailto:Tkinter-discuss@python.org">Tkinter-discuss@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tkinter-discuss" target="_blank">http://mail.python.org/mailman/listinfo/tkinter-discuss</a><br></font></blockquote></div><br>