0

I want to create a window with Tkinter. This window should have a button. When the button is pressed, I want a second window to appear (without the disappearance of the first).

The code, shortened:

from Tkinter import *
from modules.startingKit.highscore import Highscore


class OptionWindow:

    def __init__(self):
        self.master = Tk() 
        self.b4 = Button(self.master, text = "display Highscores", command = self.display()).grid(row=0, sticky = W)
    mainloop()



    def display(self):
        myWin = Toplevel()

Well, the second window IS displayed, but before I press the button. Can I change this

newnewbie
  • 993
  • 2
  • 11
  • 26

1 Answers1

6

The command attribute takes a reference to a function. When you do command=self.display(), you are calling the function and passing the result to the command attribute.

The fix is to omit the parenthesis:

self.b4 = Button(..., command=self.display, ...)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685