I am running Python on Windows. (Do not ask why....I have to!)
In the following code I do register the keyboard hit for the first run of
the program. But if I wait and then restart the run with the button command
the hit does not register.
Of course the program has to be run "directly" - not using the GUI.
Is there a solution for my problem?
Thanks, George

​from Tkinter import *
from time import sleep
import msvcrt

class Test(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.parent = master
        self.grid()
        self.button= Button(self, text="start",
        relief="raised",bd=5, padx=10, command=self.doLoop)
        self.button.grid()
        self.doLoop()

    def doLoop(self):
        n=5
        while n>0:
            print "n: ",n
            sleep(1)
            print "hit: ",msvcrt.kbhit()
            n-=1
root=Tk()
app=Test(root)
root.mainloop()

​

-- 
George Korony
AVX Corporation
801 17th Ave S.
Myrtle Beach, SC 29578
Phone: 843-444-2859
Fax: 843-444-2809
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to