Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also tried this the way heinzderaugust suggested at first:</p> <pre><code> button[i] = ttk.Button(loadProject, text=data_files[i], command = lambda i=data_files[i]:load(i)).grid(column=1, row=i, sticky=W) </code></pre> <p>I was also able to solve this by using a class as the intermediary part of the callback: (This class was inserted inside viewProject )</p> <pre><code>class Command: def __init__(self, callback, *args, **kwargs): self.callback = callback self.args = args self.kwargs = kwargs def __call__(self): return(self.callback(*self.args, **self.kwargs)) </code></pre> <p>Then I changed your button definition to:</p> <pre><code>button[i] = ttk.Button(loadProject, text=data_files[i], command = Command(load,data_files[i])).grid(column=1, row=i, sticky=W) </code></pre> <p>And finally I changed the load function to accept a argument:</p> <pre><code>def load(myFile): spamReader = csv.reader(open(myFile)) for row in spamReader: a = list(row) ttk.Label(loadProject, text=(a[0])).grid(column=4, row=0, sticky=W) ttk.Label(loadProject, text=("\n"+a[1])).grid(column=4, row=1, sticky=W) ttk.Label(loadProject, text=("\n"+a[2])).grid(column=4, row=2, sticky=W) ttk.Label(loadProject, text=(a[3])).grid(column=4, row=3, sticky=W) ttk.Label(loadProject, text=(a[4])).grid(column=4, row=4, sticky=W) ttk.Label(loadProject, text=("\n"+a[5])).grid(column=4, row=5, sticky=W) ttk.Label(loadProject, text=("\n"+a[6])).grid(column=4, row=6, sticky=W) ttk.Label(loadProject, text=("\n\n"+a[7])).grid(column=4, row=7, sticky=W) </code></pre> <p>I am unsure which would be best practice, but both do work.<br><br> (Certainly the lambda approach does sort of seem more 'pythonic')<br><br> Source: <a href="https://code.activestate.com/recipes/66521-avoiding-lambda-in-writing-callback-functions/" rel="nofollow">https://code.activestate.com/recipes/66521-avoiding-lambda-in-writing-callback-functions/</a></p>
    singulars
    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