I am trying to write a module for a button so that I don't have to rewrite the code a lot but I keep experiencing the same issue.
import pygame, sys
import tkinter
from collections import Counter as count
from pygame.locals import *
click = bool
pygame.init()
mainClock = pygame.time.Clock()
pygame.display.set_caption('CreditCard')
screen = pygame.display.set_mode((1200,800),0,32)
windowSurface = pygame.display.set_mode((1200,650),pygame.DOUBLEBUF)
font = pygame.font.SysFont(None, 35)
font2 = pygame.font.SysFont(None, 20)
ic = pygame.Color("gray15")
ac = pygame.Color(25,255,25)
PinNumber = ""
input_rect = pygame.Rect(25,25,25,25)
colour = pygame.Color('gray15')
keys = pygame.key.get_pressed()
click = pygame.MOUSEBUTTONDOWN
def card():
global click
global colour
global font
global PinNumber
def button(Num, X, Y, W, H, Action):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
click = True
button_Num = pygame.Rect(X, Y, W, H)
if button_Num.collidepoint(mouse):
if pygame.mouse.get_pressed():
for i in 2:
Action
i=i+1
mx, my = pygame.mouse.get_pos()
while True:
for event in pygame.event.get():
if event.type == QUIT:
print("Quit")
pygame.quit()
sys.exit()
#Change input_rect to the desired box
if event.type == click:
if input_rect.collidepoint(event.pos):
print("click")
button(1,30,30,100, 100, print("Clicked Button"))
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
screen.fill((255,255,255))
Image_load = pygame.image.load("Card_Scanner.jpg")
Image_load = pygame.transform.scale(Image_load, (303, 534))
screen.blit(Image_load, (90,90))
click = False
pygame.display.update()
mainClock.tick(60)
def Quit():
running = True
while running:
pygame.quit()
pygame.display.update()
mainClock.tick(60)
card()
pygame.quit()
sys.exit()
When running this, it doesn't stop printing Clicked Button while the mouse is moving I have also tried running other examples found online to the same problem Any help is really appreciated. Thanks