Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import tkinter as tk
- def new_w():
- f2 = tk.Tk()
- f2.geometry('640x480')
- f2.title('Hello')
- return f2
- class Tamagotchi:
- _name = ""
- _culture = 0
- _weight = 30
- def setName(self):
- nom = s.get()
- self._name = nom
- f.destroy()
- new_w()
- def eat(self):
- if self._weight < 41:
- self._weight += 3
- print("BUURP")
- else:
- print("Non ho fame")
- def study(self):
- x = randint(0, 9)
- y = randint(1, 9)
- r = int(input("Qual รจ il risultato di " + str(x) + "moltplicato per " + str(y)))
- if r == x * y:
- self._culture += 5
- print("Colto")
- else:
- self._culture -= 5
- print("Non colto")
- def play(self):
- if self._weight > 25:
- self._weight -= 2
- print("Oopla")
- @property
- def name(self):
- return "Hello" + self._name
- pet = Tamagotchi()
- f = tk.Tk()
- f.geometry('640x480')
- f.title('Tamagotchi')
- s = tk.Entry()
- s.place(relx=0.1, rely=0.1, anchor=tk.N)
- u = tk.Button(text="Conferma", command=pet.setName)
- u.place(relx=0.2, rely=0.1, anchor=tk.N)
- n = tk.Label(f2, textvariable=pet.name)
- n.place(relx=0.1, rely=1, anchor=tk.NW)
- s = tk.Button(f2, text="Mangia", command=pet.eat)
- s.place(relx=0.1, rely=0.1, anchor="center")
- s1 = tk.Button(f2, text="Sport", command=pet.play)
- s1.place(relx=0.4, rely=0.1, anchor="center")
- s2 = tk.Button(f2, text="Studia", command=pet.study)
- s2.place(relx=0.4, rely=0.1, anchor="center")
- '''
- v = input("Inserire nome ->")
- pet.setName(v)
- while v != 4:
- v = int(input("Scegli: 1) Mangia\n 2) Sport\n 3) Studia\n 4) Esci"))
- if v == 1:
- pet.eat()
- elif v == 2:
- pet.play()
- elif v == 3:
- pet.study()
- else:
- print("Inserire un valore corretto")
- '''
- f.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement