Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are at least a couple ways to solve your problem. Either your dialog can directly send information to the main application, or your dialog can generate an event that tells the main application that data is really to be pulled from the dialog. If the dialog simply changes the appearance of something (for example, a font dialog) I usually generate an event. If the dialog creates or deletes data I typically have it push information back to the application.</p> <p>I typically have an application object that acts as the controller for the GUI as a whole. Often this is the same class as the main window, or it can be a separate class or even defined as a mixin. This application object has methods that dialogs can call to feed data to the application.</p> <p>For example:</p> <pre><code>class ChildDialog(tk.Toplevel): def __init__(self, parent, app, ...) self.app = app ... self.ok_button = tk.Button(parent, ..., command=self.on_ok) ... def on_ok(self): # send the data to the parent self.app.new_data(... data from this dialog ...) class MainApplication(tk.Tk): ... def on_show_dialog(self): dialog = ChildDialog(self) dialog.show() def new_data(self, data): ... process data that was passed in from a dialog ... </code></pre> <p>When creating the dialog, you pass in a reference to the application object. The dialog then knows to call a specific method on this object to send data back to the application.</p> <p>If you're not into the whole model/view/controller thing you can just as easily pass in a function rather than an object, effectively telling the dialog "call this function when you want to give me data".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload