python - Get a TK() object from another method -


target

I want to create a popup window with a button, which is when the mouse leaves the window Stops. (This is a submenu of a program.)

To do this, I have a function that is called to open a popup window. It has the following code:
  master = tc () fpy.ui.menu.submenu (master = master, [... more parameters ...]) mainloop ()  

And one way to make everything (fpy.ui.menu.submenu (...)). This function should be as clean as possible. This is part of an API which I am making for my future projects. Def submenu (master, [... more parameters ...]): master.overrideredirect (true) a_frame = frame (master, bg = "gray") # [generate button To codeblock] a_frame.bind ("go left", delete) a_frame.pack ()

  a_frame dam ("leave & lt; The function function is called, when the mouse leaves the frame and now my problem begins, 'deleted' function is called my root (in this case the master is called ) Should be destroyed.  

Problem:
  DRF (): # How can I get master-object? Master.destroy ()  

This will make an error!

information:

  • The function starts' destroying '
  • I did' manage to transmitter as the main object parameter
  • Please ignore dots at the beginning of a line Stack exchange editor does not accept indent code.
  • option 1: pass it an argument

    You can make a lambda statement by using your delete () function:

      a_frame.  

    Then modify the signature of your deleted function:

      DRF (master)): Master.destroy ()  

    Option 2: Call the demolition method directly on the master

    same lambda statement as before, we call it method instead of dealing with it directly to any other function We do.

      a_frame.bind ("leave <">, lambda: master.destroy ())  

    Of course, this is not an option If you want to do other stuff in your delete () function.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -