OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python - change function's variable inside another function via argument [duplicate]

  • Thread starter Thread starter ariel
  • Start date Start date
A

ariel

Guest
I want to find how to change a variable via a function that isn't the one that the variable initiated in using the other function's argument (to make it viable for many usages).

something along this lines:

Code:
from tkinter import *

class app(TK):
   def __init__(self):
      super().__init__()
      self.window = Text(self)
   ...

   def change_var(self, variable):
      variable = not(variable)  
 
   def first_fucn(self):
      some_variable = True
      print(some_variable) # True
      self.window.bind('<Return>'>, lambda: self.change_var(some_variable))
      # event is activated once for example
      print(some_variable) # False

the problem that it doesn't only need to change the variable's value, it need to store that information in the specific variable that I sent through the function. then you might ask yourself, when didn't I use return, and the answer is it because in my program the function is called through an exterior event - so in short I can't relay on this solution - I need to make the value and the assignment in the specialized function, and because that the range of variables is a lot, I need a solution that will work every time
<p>I want to find how to change a variable via a function that isn't the one that the variable initiated in using the other function's argument (to make it viable for many usages).</p>
<p>something along this lines:</p>
<pre class="lang-py prettyprint-override"><code>from tkinter import *

class app(TK):
def __init__(self):
super().__init__()
self.window = Text(self)
...

def change_var(self, variable):
variable = not(variable)

def first_fucn(self):
some_variable = True
print(some_variable) # True
self.window.bind('<Return>'>, lambda: self.change_var(some_variable))
# event is activated once for example
print(some_variable) # False
</code></pre>
<p>the problem that it doesn't only need to change the variable's value, it need to store that information in the specific variable that I sent through the function.
then you might ask yourself, when didn't I use <code>return</code>,
and the answer is it because in my program the function is called through an exterior event - so in short I can't relay on this solution - I need to make the value and the assignment in the specialized function, and because that the range of variables is a lot, I need a solution that will work every time</p>
 

Latest posts

Top