Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You didn't specify any error messages, but it's most likely that you're doing <code>fuctions.one()</code> - actually calling the one() function of that module <em>before the Button is created</em>. It's simply fixed by removing the () part - when you specify a function without (), you are passing a reference of the function object.</p> <p>Also keep in mind the scope of the <code>code_entry</code> variable - if you were using it as a module level global before (or function local, if <code>one()</code> was inside the same function as your <code>ttk.Button</code> call), it won't be available when you move it to a new namespace without <code>code_entry</code>.</p> <p>To solve this you should pass <code>code_entry</code> as a parameter to the callback <strong>without</strong> calling <code>one()</code> at first. The usual approach for this is creating a lambda - essentially creating a function that works on the same scope of the original <code>one()</code>, having access to variables like <code>code_entry</code>, but also calling a function in a different module.</p> <pre><code>ttk.Button(mainframe, text="1", command=lambda: functions.one(code_entry)) </code></pre> <p>Note that this is basically the same as:</p> <pre><code>def some_anonymous_function(): functions.one(code_entry) ttk.Button(mainframe, text="1", command=some_anonymous_function) </code></pre> <p>Both examples create a function object and pass that object as reference - the <code>functions.one()</code> call of the lambda is actually inside the body of the lambda function, to be called later by tkinter.</p> <p>Of course you also have to redefine one() to accept this new parameter:</p> <pre><code>def one(code_entry): code_entry.insert(END,"1") </code></pre>
    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.
 

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