Python Forum
Problems with loading buttons (pygame)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with loading buttons (pygame)
#1
I am making a game which is so far good, but after the player fills in all the info, it doesn't display the buttons. The shell is in typable mode (Can't type commands). I don't know how to fix it can someone please tell me what I'm doing wrong. Thx

The Button Func on line 58 and executed on lines 96 and 97 inside Game_Func
import pygame
import random
import time

pygame.init()
#GameData
signInList = {'Sheepposu' : 'rachl032078', 'gg' : 'rachl1979'}

#Variables

#Colors
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
darker_red = (200,0,0)
green = (0,255,0)
blue = (0,0,255)
CustomColor1 = (48,150,140)
CustomColor2 = (36,112.5,105)
Unique_Color = (190,140,210)
ColorList = [black, red, green, blue]
Confirm = True

#Game Config
display_width = 1000
display_height = 800
pd = pygame.display
gD = pygame.display.set_mode((display_width,display_height))
fps = 100
pd.set_caption('Game')
clock = pygame.time.Clock()
gD.fill(blue)
clock.tick(fps)

pygame.display.update()

#functions
def SignIn():
    global signInList
    username = input('(Type "new" for new player) Username: ')

    if username == 'new':
        newUsername = input('Type your Username: ')
        newPassword = input('Type your Password: ')
        signInList = {'Sheepposu' : 'rachl032078',
                      newUsername : newPassword}
        Game_Func(username)

    else:
        if username in signInList:
            password = input('Please type your password: ')
            if password == signInList[username]:
                Game_Func(username)
        else:
            print('Invalid Username')
            SignIn()

def Button(Butx, Buty, Butx2, Buty2, Butcolor, ShadowColor, text, textsize, textcolor, textFont, command=None, command2=None):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    smallText = pygame.font.SysFont(textFont, textsize)
    textSurf, textRect = text_objects(text, smallText)
    textRect.center = ((Butx + (Butx2/2)), Buty + (Buty2/2))
    pygame.draw.rect(gD, Butcolor, (Butx, Buty, Butx2, Buty2))
    gD.blit(textSurf, textRect)
    if Butx + Butx2 > mouse[0] > Butx and Buty + Buty2 > mouse[1] > Buty: 
        pygame.draw.rect(gD, ShadowColor, (Butx, Buty, Butx2, Buty2))
        gD.blit(textSurf, textRect)
        if click[0] == 1:
            if command != None:
                command()
            if command2 != None:
                command2()
    else:
        pygame.draw.rect(gD, Butcolor, (Butx, Buty, Butx2, Buty2))
        gD.blit(textSurf, textRect)
    pygame.display.update()

def message_display(text, size, centerX, centerY):
    font = pygame.font.SysFont('arial', size)
    textSurf, TextRect = text_objects(text, font)
    TextRect.center = ((centerX),(centerY))
    gD.blit(textSurf, TextRect)

    pygame.display.update()

def text_objects(text, font):
    textSurface = font.render(text, True, Unique_Color)
    return textSurface, textSurface.get_rect()

def Game_Func(username):
    global Confirm
    while Confirm:
        gD.fill(blue)
        message_display('You\'re %s, correct?' %username, round(display_width/17), round(display_width/2), display_height * .25)
        Button(round(display_width * .3), round(display_height * .7), round(display_width * .4), round(display_height * .2), CustomColor1, CustomColor2, 'Confirm!', round(display_width/20), blue, 'arial', Game_Func2)
        Button(round(display_width * .75), round(display_height * .8), round(display_width * .2), round(display_height * .1), red, darker_red, "No!", round(display_width/50), blue, 'arial', SignIn)
        
        clock.tick(15)

def Game_Func2():
    global Confirm
    Confirm = False
    End_Game()

def End_Game():
    print(signInList)

message_display('Please fill in info on the console', round(display_width/20), round(display_width/2), round(display_height/2))
SignIn()
Reply


Messages In This Thread
Problems with loading buttons (pygame) - by SheeppOSU - Apr-12-2019, 01:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame installation problems Gheryk 5 8,713 Nov-29-2023, 08:49 PM
Last Post: E_Mohamed
  [PyGame] pygame-manu : using controller buttons to move around menu mlw19mlw91 2 1,673 Mar-12-2023, 01:55 PM
Last Post: deanhystad
  [PyGame] Problems with jump code in pygame Joningstone 4 5,433 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  Pygame - Images As Buttons vman44 3 13,080 Mar-20-2020, 08:13 PM
Last Post: vman44
  [PyGame] pygame image loading error BlueClaw 6 6,445 Dec-10-2019, 08:50 PM
Last Post: BlueClaw
  [Pygame] Problems with my textbox SheeppOSU 1 3,121 May-27-2019, 12:03 AM
Last Post: metulburr
  [pygame] Inventory problems. Weapons equipped to wrong slot SheeppOSU 6 4,075 May-07-2019, 02:46 AM
Last Post: SheeppOSU
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,773 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  drawing, moving, and collision problems (pygame) SheeppOSU 26 14,960 Apr-22-2019, 03:09 AM
Last Post: SheeppOSU
  Buttons in PyGame mzmingle 4 13,108 Oct-09-2018, 05:19 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020