V
V
⚡Valery⚡2015-09-30 19:48:15
Python
⚡Valery⚡, 2015-09-30 19:48:15

How to do Function Interaction?

def FS():
    a = edit1.get()
    b = edit2.get()
    c = edit3.get()
    print(a,b,c)

def Test():

    root1 = Tk()
    root.title('FTP Host')
    label1 = Label(root1,text='H')
    label2 = Label(root1,text='L')
    label3 = Label(root1,text='P')

    label1.grid(row = 0, column = 0)
    label2.grid(row = 1, column = 0)
    label3.grid(row = 3, column = 0)

    edit1 = Entry(root1)
    edit2 = Entry(root1)
    edit3 = Entry(root1)

    edit1.grid(row = 0, column = 1)
    edit2.grid(row = 1, column = 1)
    edit3.grid(row = 3, column = 1)
    b = Button(root1,text='Вычислить',command = FS)
    b.grid()

root = Tk()
b2 = Button(root,text='Test',command=Test)
b2.grid()
root.mainloop()

He does not understand what edit1 is how to fix it please tell me
--------------------
NameError: name 'edit1' is not defined

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MK, 2015-09-30
@Maxsior

global edit1you need to add it to both functions, in general, read about this operator

A
abcd0x00, 2015-10-01
@abcd0x00

They must be in the same class and communicate through it.

>>> class A:
...     def f1(self):
...         self.x = 1
...     def f2(self):
...         self.x = 2
...     def f3(self):
...         print(self.x)
... 
>>> a = A()
>>> a.f1()
>>> a.f3()
1
>>> a.f2()
>>> a.f3()
2
>>>

The principle is the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question