Simple TK Question - refreshing the canvas when not in focus

blaine frikker at gmail.com
Wed Apr 30 10:18:30 EDT 2008


Still doesn't work.  I'm looking into using wx instead...

This is the full code - does it work for anyone else? Just do a echo
'line 0 0 10 10' > dev.file


import sys, os, time, Tkinter, threading

class nokia_fkscrn(Tkinter.Toplevel):
    fp=None
    def __init__(self, file):
        self.fname = file
        # Create the FIFO pipe (hopefully /dev/screen or similar)
        if not os.path.exists(self.fname): os.mkfifo(self.fname)
        self.readthread = threading.Thread(target=self.read)
        self.readthread.start()
        self.init_canvas()

    def init_canvas(self):
        # Set up our canvas
        self.root = Tkinter.Tk()
        self.root.title('Nokia Canvas')
        self.canvas = Tkinter.Canvas(self.root, width =130,
height=130)

        self.canvas.pack()
        self.root.mainloop()


    def read(self):
        while 1:
            self.fp = open(self.fname, 'r')
            while 1:
                st = self.fp.readline()
                if st == '': break
                self.process(st)
            self.fp.close()

    def process(self, line):
        cmd = line.split()
        if cmd[0] == 'line':
            # Draw Line
            args = map(int, cmd[1:])
            try:
                color=args[4]
            except:
                color='black'
            if self.canvas:
                print 'Drawing Line:', args
                self.canvas.create_line(args[0], args[1], args[2],
args[3], fill=color)
                self.canvas.update()
                self.canvas.focus_force()

nokia = nokia_fkscrn('dev.file')



More information about the Python-list mailing list