Python Forum

Full Version: I think this is a problem with returning? maby?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import Button
import Menues
import pygame
import sys
from pygame.locals import *
x = 0
y = 30
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)

pygame.font.init()

pygame.init()
infoObject = pygame.display.Info()
correctedscreenheight= (infoObject.current_h - 30)
screen = pygame.display.set_mode((infoObject.current_w, correctedscreenheight))
screenxsize = infoObject.current_w
screenysize = infoObject.current_h
pygame.display.set_caption('Dnd reimagined')
mainscreen = pygame.image.load("dnd.png").convert()
WHITE = (25 , 25, 25)
fuckoff = Button.button()
buttoncolorinner = (200, 200, 200)
buttoncolorouter = (50, 50, 50)
bxp = (infoObject.current_w / 2)
byp = (correctedscreenheight / 2)
startbuttonstuff = Menues


def keyhandler():
    mpos = pygame.mouse.get_pos()
    clicky = pygame.mouse.get_pos()
    pressed = pygame.mouse.get_pressed()
    startthings = startbuttonstuff.Menues.startmenue
    bxp = startthings[0]
    byp = startthings[1]
    bxw = startthings[2]
    byw = startthings{3}

    otherxcornerofbutton = bxp + bxw
    otherycornerofbutton = byp + byw

    if pressed[0] == 1 and bxp < clicky[0] < otherxcornerofbutton and byp < clicky[1] < otherycornerofbutton:
        buttoncolorinner = (50, 50, 50)
        buttoncolorouter = (200, 200, 200)
        startbuttonstuff.Menues.startmenue()
    else:
        buttoncolorinner = (200, 200, 200)
        buttoncolorouter = (50, 50, 50)
        startbuttonstuff.Menues.startmenue()

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.display.quit()
            pygame.quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:

                if bxp < mpos[0] < otherxcornerofbutton and byp < mpos[1] < (otherycornerofbutton):
                    fuckoff.click()






while True:

    mainscreen = pygame.transform.scale(mainscreen, (infoObject.current_w, infoObject.current_h))



    screen.blit(mainscreen, (0, 0))

    keyhandler()



    pygame.display.update()
class Menues:

    def __call__(self):
        a=1

    def __init__(self):
        a=1

    def charactormenue(self):

        a=1

    def startmenue(screenxsize, screenysize, bxp, byp)
:

        bxw = 200
        byw = 150
        bxp = bxp - (bxw // 2)
        byp = byp - byw // 2)
        textforbutton = ("Start")
        return bxp, byp, bxw, byw, textforbutton
import pygame


class button:
    def __init__(self):
        a=1



    def __call__(self):
        a=1


    def draw(self, screen, buttoncolorinner, buttoncolorouter, bxp, byp, bxw, byw, textforbutton):
        innerbuttonxpos = bxp + ((bxw * .1)//2)
        innerbuttonoutlinewidth = bxw * .9
        innerbuttonypos = byp + ((byw * .1)//2)
        innerbuttonoutlineheight =  byw * .9
        textsize = bxw * .3
        textsize = int(textsize)

        maintext = pygame.font.SysFont('Comic Sans MS', textsize)
        buttontext = maintext.render(textforbutton, False, (0, 0, 0))

        pygame.draw.rect(screen, buttoncolorouter, (bxp, byp, bxw, byw))

        pygame.draw.rect(screen, buttoncolorinner, (innerbuttonxpos, innerbuttonypos, innerbuttonoutlinewidth, innerbuttonoutlineheight))
        screen.blit(buttontext, ((innerbuttonxpos + 10), (innerbuttonypos + 10)))
        return

    def click(self):
        a=1
errors:
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:/Users/Blue/Desktop/CompDnd/Main.py", line 75, in <module>
keyhandler()
File "C:/Users/Blue/Desktop/CompDnd/Main.py", line 35, in keyhandler
bxp = startthings[0]
TypeError: 'function' object is not subscriptable

Process finished with exit code 1




I think maby there is something wrong with getting the values from the class startmenue, but i am lost. help would be greatly appreciated. Thanks!
Line 34. You forgot the arguments.
startthings = startbuttonstuff.Menues.startmenue
startthings = startbuttonstuff.Menues.startmenue(arguments here)
line 38. change {} to [].
import Button
import Menues
import pygame
import sys
from pygame.locals import *
x = 0
y = 30
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)

pygame.font.init()

pygame.init()
infoObject = pygame.display.Info()
correctedscreenheight= (infoObject.current_h - 30)
screen = pygame.display.set_mode((infoObject.current_w, correctedscreenheight))
screenxsize = infoObject.current_w
screenysize = infoObject.current_h
pygame.display.set_caption('Dnd reimagined')
mainscreen = pygame.image.load("dnd.png").convert()
WHITE = (25 , 25, 25)
fuckoff = Button.button()
buttoncolorinner = (200, 200, 200)
buttoncolorouter = (50, 50, 50)
bxp = (infoObject.current_w / 2)
byp = (correctedscreenheight / 2)
startbuttonstuff = Menues.Menues.startmenue(screenxsize, screenysize)


def keyhandler():
    mpos = pygame.mouse.get_pos()
    clicky = pygame.mouse.get_pos()
    pressed = pygame.mouse.get_pressed()
    bxp = startbuttonstuff[0]
    byp = startbuttonstuff[1]
    bxw = startbuttonstuff[2]
    byw = startbuttonstuff[3]

    otherxcornerofbutton = bxp + bxw
    otherycornerofbutton = byp + byw

    if pressed[0] == 1 and bxp < clicky[0] < otherxcornerofbutton and byp < clicky[1] < otherycornerofbutton:
        buttoncolorinner = (50, 50, 50)
        buttoncolorouter = (200, 200, 200)
        startbuttonstuff.Menues.startmenue()
    else:
        buttoncolorinner = (200, 200, 200)
        buttoncolorouter = (50, 50, 50)
        startbuttonstuff.Menues.startmenue()

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.display.quit()
            pygame.quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:

                if bxp < mpos[0] < otherxcornerofbutton and byp < mpos[1] < (otherycornerofbutton):
                    fuckoff.click()






while True:

    mainscreen = pygame.transform.scale(mainscreen, (infoObject.current_w, infoObject.current_h))



    screen.blit(mainscreen, (0, 0))

    keyhandler()



    pygame.display.update()
did as asked, it did not work, says that it needs a positional argunent, which i could swear was defined on line 27. this is confusing, am i missing a hidden space or something?
startbuttonstuff = Menues
should be
startbuttonstuff = Menues()
just says it is not callable when i do that, despite the fact that menues has a call function.

import Button
import Menues
import pygame
import sys
from pygame.locals import *
x = 0
y = 30
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)

pygame.font.init()

pygame.init()
infoObject = pygame.display.Info()
correctedscreenheight= (infoObject.current_h - 30)
screen = pygame.display.set_mode((infoObject.current_w, correctedscreenheight))
screenxsize = infoObject.current_w
screenysize = infoObject.current_h
pygame.display.set_caption('Dnd reimagined')
mainscreen = pygame.image.load("dnd.png").convert()
WHITE = (25 , 25, 25)
fuckoff = Button.button()
buttoncolorinner = (200, 200, 200)
buttoncolorouter = (50, 50, 50)
bxp = (infoObject.current_w / 2)
byp = (correctedscreenheight / 2)
startbuttonstuff = Menues()


def keyhandler():
    mpos = pygame.mouse.get_pos()
    clicky = pygame.mouse.get_pos()
    pressed = pygame.mouse.get_pressed()
    bxp = startbuttonstuff[0]
    byp = startbuttonstuff[1]
    bxw = startbuttonstuff[2]
    byw = startbuttonstuff[3]

    otherxcornerofbutton = bxp + bxw
    otherycornerofbutton = byp + byw

    if pressed[0] == 1 and bxp < clicky[0] < otherxcornerofbutton and byp < clicky[1] < otherycornerofbutton:
        buttoncolorinner = (50, 50, 50)
        buttoncolorouter = (200, 200, 200)
        startbuttonstuff.Menues.startmenue()
    else:
        buttoncolorinner = (200, 200, 200)
        buttoncolorouter = (50, 50, 50)
        startbuttonstuff.Menues.startmenue()

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.display.quit()
            pygame.quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:

                if bxp < mpos[0] < otherxcornerofbutton and byp < mpos[1] < (otherycornerofbutton):
                    fuckoff.click()






while True:

    mainscreen = pygame.transform.scale(mainscreen, (infoObject.current_w, infoObject.current_h))



    screen.blit(mainscreen, (0, 0))

    keyhandler()



    pygame.display.update()
Sorry forgot to look at your imports.
startbuttonstuff = Menues.Menues()

Example
class A:
    def __init__(self):
        print('init')

    def __call__(self):
        print('call')

a = A() # __init__
a() # __call__

python let you unpacked.
bxp = startbuttonstuff[0]
    byp = startbuttonstuff[1]
    bxw = startbuttonstuff[2]
    byw = startbuttonstuff[3]
also could do this.
bxy, byp, bxw, byw = startbuttonstuff[0:4]
import Button
import Menues
import pygame
import sys
from pygame.locals import *
x = 0
y = 30
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)

pygame.font.init()

pygame.init()
infoObject = pygame.display.Info()
correctedscreenheight= (infoObject.current_h - 30)
screen = pygame.display.set_mode((infoObject.current_w, correctedscreenheight))
screenxsize = infoObject.current_w
screenysize = infoObject.current_h
pygame.display.set_caption('Dnd reimagined')
mainscreen = pygame.image.load("dnd.png").convert()
WHITE = (25 , 25, 25)
fuckoff = Button.button()
buttoncolorinner = (200, 200, 200)
buttoncolorouter = (50, 50, 50)
bxp = (infoObject.current_w / 2)
byp = (correctedscreenheight / 2)
startbuttonstuff = Menues.Menues()
startbuttonstuff.startmenue(screenxsize, screenysize)

def keyhandler():
    mpos = pygame.mouse.get_pos()
    clicky = pygame.mouse.get_pos()
    pressed = pygame.mouse.get_pressed()
    bxp = startbuttonstuff[0]
    byp = startbuttonstuff[1]
    bxw = startbuttonstuff[2]
    byw = startbuttonstuff[3]

    otherxcornerofbutton = bxp + bxw
    otherycornerofbutton = byp + byw

    if pressed[0] == 1 and bxp < clicky[0] < otherxcornerofbutton and byp < clicky[1] < otherycornerofbutton:
        buttoncolorinner = (50, 50, 50)
        buttoncolorouter = (200, 200, 200)
        startbuttonstuff.Menues.startmenue()
    else:
        buttoncolorinner = (200, 200, 200)
        buttoncolorouter = (50, 50, 50)
        startbuttonstuff.Menues.startmenue()

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.display.quit()
            pygame.quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:

                if bxp < mpos[0] < otherxcornerofbutton and byp < mpos[1] < (otherycornerofbutton):
                    fuckoff.click()






while True:

    mainscreen = pygame.transform.scale(mainscreen, (infoObject.current_w, infoObject.current_h))



    screen.blit(mainscreen, (0, 0))

    keyhandler()



    pygame.display.update()
class Menues:

    def __call__(self):
        a=1

    def __init__(self):
        a=1

    def charactormenue(self):

        a=1

    def startmenue(self, screenxsize, screenysize):
        bxp = screenxsize
        byp = screenysize
        bxw = 200
        byw = 150
        bxp = bxp - (bxw // 2)
        byp = byp - (byw // 2)
        textforbutton = ("Start")
        return bxp, byp, bxw, byw, textforbutton
menus object does not support indexing? this is getting frustrating, a google search has not helped. i return the values, i should be able to access them.
Okay.
Menues.Menues() create and class object.
menus = Menus.Menus()
Now you can get the startbuttonstuff
startbuttonstuff = menus.startmenue(screenxsize, screenysize)
Line 45 & 49. I don't know what you want here.
But this is not going to work
startbuttonstuff.Menues.startmenue()
okay, so line 45 and 49 were just the result of desperation trying to figure out the issue, i do not think even i knew what the heck i was trying to do. deleted. So the issue was that i needed to make an instance of the class, then "ask" the class to run startmenue, instead of asking the class itself instead of the instance. I might be completely wrong though. Thanks for the help!