Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

OOP loading the event listener.. not working

I'm adept or just plain shit at this lol this is the error message
Code
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
TypeError: transfer() takes exactly 3 arguments (1 given)

how do I fix this.. or make this code better to work like a fake paypal? lol

Code
from Tkinter import *
#window create

class Person(Frame):
    def __init__(self,name):
        Frame.__init__(self,name)
        self.grid()
        self.button_clicks =0 #wtf clicks
        self.create_widgets()
        self.name = name
        self.money = 0
    def create_widgets(self):
        self.button1 = Button(self)
        self.button1["text"] = "amount of fucks givin: 0"
        self.button1["command"] = self.transfer
        self.button1.grid()
        self.button1.configure(text = "Send Money")
    def transfer(sender,reciever,amount):
        if sender.money >=amount:
            sender.money -= amount
        else:
            raise Exception
        reciever.money += amount
root = Tk()
root.title("Fake Paypal")
root.geometry("900x500")
app = Person(root)
app.grid()




class Iced_Coffee:
    def __init__(Taylor,name):
        Taylor.name = name
        Taylor.money = 0

    
Taylor = Iced_Coffee("Taylor")
#kickoff loop mofo
root.mainloop()
Quote:how do I fix this


Your transfer function is lacking of information.

Your code is in general really messy. Please, take the time to read this common style guide: python.org/dev/peps/pep-0008/

For this project you need more basic skills. Try to work with functions before you go for classes/ OOP.

Try to make more baby steps in your code, like:

1. Create form
2. Create button
3. Theory: How does tkinter work with classes/function
4. Create a function that send money
5. Create a function that saves the money
and
so
on
Two problems here.

1) transfer() is a member function of your class Person. Every member function has to begin with the "self" argument if it isn't static.
def transfer(sender,reciever,amount) should be def transfer(self, sender, reciever, amount)

2) The error message you're getting means you're calling person.transfer() with too few arguments. Your function wants 3 (with the "self" it's actually 4, but that's passed automatically), but python is telling you it only received 1 argument (namely the automatic "self" argument).


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Krash39Oct 26, 2019 08:05 PM 14 339 Oct 26, 2019 08:05 PM
Last Post: datguy.dev
[Java] by magicpartySep 4, 2019 05:43 AM 4 286 Sep 4, 2019 05:43 AM
Last Post: newQuery
[Java] by Consulting DetectiveJul 16, 2018 12:55 PM 5 261 Jul 16, 2018 12:55 PM
Last Post: Caliban