1
votes

I have a program that has a message box to instruct the user. But after I close the message box, I can't enter in the entry widget. Has anyone got an idea of what could be the problem?

My code:

from tkinter import *
import random
import tkinter.messagebox

class Application(Frame):
    """ GUI aplication hoger of lager"""
    def __init__(self,master):
        """Instaleerd het Frame"""
        super(Application, self).__init__(master)
        self.grid()
        rarara=0;aantal=0;max_pogingen=10;ikdenkaan=random.randrange(1,100)
        self.main()

    def welkom(self):
        """Create Widgets voor het spelletje hoger of lager"""
        #Verwelkomingslebels en instructielabels
        msgb=tkinter.messagebox.showinfo("uitleg",
                                         "Welkom bij het spelletje'hoger of lager'.\nIk heb zojuist aan een getal tussen 1 en 100 gedacht.\nJij mag dat getal raden en je hebt 10 pogingen."
                                         )

    def labels(self):
        #ik denk aan label
        Label(self,
              text="Ik denk aan:"
              ).grid(row=0,column=0,sticky=W)


    def welkgetal(self):
        rarara=Entry(self)
        rarara.grid(row=0, column=1,sticky=W)
        rarara.configure(state="normal")


    def main(self):
        self.welkom()
        self.labels()
        self.welkgetal()

root=Tk()
root.title("Hoger of lager")
root.geometry("350x280+533+244")
app=Application(root)
root.mainloop()
1

1 Answers

3
votes

It seems that Tk modal window behave in a really weird way for event handling :

[0] Python tkinter: stopping event propagation in text widgets tags

[1]http://tiku.io/questions/3361808/python-tkinter-bind-breaking

The fix :

class Application(Frame):
    """ GUI aplication hoger of lager"""
    def __init__(self,master):
        """Instaleerd het Frame"""
        super(Application, self).__init__(master)
        self.grid()
        rarara=0;aantal=0;max_pogingen=10;ikdenkaan=random.randrange(1,100)
        self.main()
        master.after(1, self.welkom)

    def main(self):
        self.labels()
        self.welkgetal()

I don't know why, but it works.