Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Kako accessovati funkciju iz funkcije?

[es] :: Python :: Kako accessovati funkciju iz funkcije?

[ Pregleda: 7147 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Kako accessovati funkciju iz funkcije?31.03.2017. u 17:09 - pre 85 meseci
Pravim jednostavan GUI program u Pythonu, imam problem sa accessovanjem funkcije iz funkcije (ako me razumete). Hoću da pristupim funkciji addItem() iz funkcije display().

Code:
# priorities.py
#   GUI program to manage priorities

from tkinter import *

class Priority:

    def __init__(self, subject, priority):
        self.subject = subject
        self.priority = priority

    def subject(self):
        return self.subject

    def priority(self):
        return self.priority


class GuiPart:

    def __init__(self):
        self.root = self.createWindow()

    def createWindow(self):

        root = Tk()
        root.resizable(width = False, height = False)
        root.title("Priorities")

        return root

    def display(self):

        listBox = Listbox().grid(row=1)

        buttonAdd = Button(text = "Add").grid(row = 2,
                                  column = 0,
                                  sticky = W,
                                  command = g.addItem)

        buttonRemove = Button(text="Remove").grid(row = 2,
                                   column = 0,
                                   sticky = W,
                                   command = g.removeItem)

        buttonEdit = Button(text="Edit").grid(row = 2,
                                 column = 0,
                                 sticky = E,
                                 command = g.editItem)

        textBox = Text().grid(row = 3)

    def addItem(self):
        item = Priority(self.subject, self.priority)
        item.subject = g.textBox.get("1.0", 'end-1c')

        g.listBox.insert(END, self)

class Client:
    pass

if __name__ == "__main__":
    g = GuiPart()
    g.display()
    g.root.mainloop()






Evo šta javlja:

Citat:
/usr/bin/python3.5 /home/cali/PycharmProjects/priorities/priorities.py
Traceback (most recent call last):
File "/home/cali/PycharmProjects/priorities/priorities.py", line 70, in <module>
g.display()
File "/home/cali/PycharmProjects/priorities/priorities.py", line 39, in display
command = g.addItem)
File "/usr/lib/python3.5/tkinter/__init__.py", line 2077, in grid_configure
+ self._options(cnf, kw))
_tkinter.TclError: bad option "-command": must be -column, -columnspan, -in, -ipadx, -ipady, -padx, -pady, -row, -rowspan, or -sticky

Process finished with exit code 1
 
Odgovor na temu

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Re: Kako accessovati funkciju iz funkcije?01.04.2017. u 09:45 - pre 85 meseci
Problem je bio što je command = addItem bilo u konstruktoru za grid, a ne za Button().
 
Odgovor na temu

[es] :: Python :: Kako accessovati funkciju iz funkcije?

[ Pregleda: 7147 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.