Fixed Crash in TextButton().update():
New button had wrong parameters.
This commit is contained in:
parent
c0aafce29a
commit
d89e8bf96e
1 changed files with 11 additions and 6 deletions
17
pg.py
17
pg.py
|
@ -30,7 +30,7 @@ class Hover:
|
||||||
self.x, self.y = position
|
self.x, self.y = position
|
||||||
self.w, self.h = size
|
self.w, self.h = size
|
||||||
|
|
||||||
elif position is Callable:
|
elif callable(position):
|
||||||
self.x, self.y = position()
|
self.x, self.y = position()
|
||||||
self.callable_position = position
|
self.callable_position = position
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class Hover:
|
||||||
mx, my = mouse_pos
|
mx, my = mouse_pos
|
||||||
|
|
||||||
if not self.ca is None:
|
if not self.ca is None:
|
||||||
|
print(type(self.ca))
|
||||||
if self.ca.collidepoint((mx, my)):
|
if self.ca.collidepoint((mx, my)):
|
||||||
if self.function is None:
|
if self.function is None:
|
||||||
return True
|
return True
|
||||||
|
@ -74,7 +75,7 @@ class Button:
|
||||||
self.x, self.y = position
|
self.x, self.y = position
|
||||||
self.width, self.height = size
|
self.width, self.height = size
|
||||||
|
|
||||||
elif position is Callable:
|
elif callable(position):
|
||||||
self.x, self.y = position()
|
self.x, self.y = position()
|
||||||
self.callable_position = position
|
self.callable_position = position
|
||||||
|
|
||||||
|
@ -83,6 +84,8 @@ class Button:
|
||||||
self.ca = ca
|
self.ca = ca
|
||||||
self.key = key
|
self.key = key
|
||||||
|
|
||||||
|
print(type(ca))
|
||||||
|
|
||||||
self.hover = Hover(function, ca, position, size)
|
self.hover = Hover(function, ca, position, size)
|
||||||
|
|
||||||
if buttonlist:
|
if buttonlist:
|
||||||
|
@ -111,7 +114,7 @@ class TextButton:
|
||||||
self.padding = padding
|
self.padding = padding
|
||||||
self.callable_position = None
|
self.callable_position = None
|
||||||
|
|
||||||
if position is tuple:
|
if type(position) is tuple:
|
||||||
self.position = position
|
self.position = position
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -168,7 +171,7 @@ class TextButton:
|
||||||
if not new_callable_pos is None:
|
if not new_callable_pos is None:
|
||||||
new_pos = new_callable_pos(self.size)
|
new_pos = new_callable_pos(self.size)
|
||||||
|
|
||||||
elif new_pos is tuple:
|
elif type(new_pos) is tuple:
|
||||||
new_callable_pos = None
|
new_callable_pos = None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -189,10 +192,12 @@ class TextButton:
|
||||||
self.surface = new_surface
|
self.surface = new_surface
|
||||||
self.function = new_func
|
self.function = new_func
|
||||||
|
|
||||||
self.button = Button(new_func, new_bg_color, key=new_key)
|
|
||||||
|
|
||||||
self.background = self.generate_background()
|
self.background = self.generate_background()
|
||||||
|
|
||||||
|
self.button = Button(new_func, self.background, key=new_key)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def blit(self, surface: pygame.Surface=None):
|
def blit(self, surface: pygame.Surface=None):
|
||||||
x, y = self.position
|
x, y = self.position
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue