List Override Issue Where 2 Completely Unrelated List Share Values

What I mean is that lists randomly decide to merge and combine values. I’m on Python 3.10.6. The lists are “buttons” (for storing button instances) and “keys” (for storing keys pressed). The issue specifically is in my Pause Menu. These lists stay separate anywhere else, but in the pause menu, the buttons list decides to share values with keys. Here is the entire pause script. The bottom is the part that matters, but I want to send in the whole thing anyway to be more specific.

def Pause():
    global menu , paused , running , screen , WinProps , clock , FPS , scrwidth , scrheight , keys , event , buttons , frame , audio
    WinProps[2].set_alpha(162.5)
    font = pygame.font.Font(resource_path(r'AssetsWindowPixelifySans-VariableFont_wght.ttf') , round(64 * scale))
    text = font.render('Pause (Esc to Exit)' , True , (255 , 255 , 255) , (27 , 27 , 27))
    textSurf = text.get_rect()
    textSurf.center = (scrwidth / 2 , 50 * scale)
    screen.blit(pygame.transform.scale(WinProps[2] , (scrwidth , scrheight)) , (0 , 0))
    screen.blit(text , textSurf)
    if not menu:
        buttons.append(Button(pygame.image.load(resource_path(r'AssetsWindowButtonsmenu.png')) , (300 , 300) , 'Menu'))
    while paused:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                paused = False
            elif event.type == pygame.VIDEORESIZE:
                scrwidth , scrheight = event.size
                WindowSize(scrheight)
            elif event.type == pygame.KEYDOWN:
                HandleKey('ESCAPE' , 'KEYDOWN')
            elif event.type == pygame.KEYUP:
                HandleKey('ESCAPE' , 'KEYUP')
        DisplayButtons()
        print(buttons , keys)
        for button in buttons:
            if 'ESCAPE' in keys or button.is_pressed():
                pygame.mixer.unpause()
                paused = False
                if button.is_pressed():
                    menu = True
                    pygame.mixer.stop()
                    audio[0].play()
                    frame = 1
        pygame.display.flip()

From the print() block, you would expect it to return button instances and keys preessed, but instead they merge into one list. Here is the output:

[<Assets.button.Button object at 0x000002151DCC1B10>] [<Assets.button.Button object at 0x000002151DCC1B10>]

Also, I made a system in DisplayButtons() to eradicate non-Button instances (int , str , etc.). I decided for debug purposes to include a print() function to print the non-Button instances. Here is what it finds (the output):

ESCAPE

If it matters, here is the DisplayButtons() function.

def DisplayButtons():
    global buttons , screen , scale , nmp
    itemDel = []
    for button in buttons:
        if not isinstance(button , Button):
            itemDel.append(button)
            continue
        w , h = (button.sprite.get_width() , button.sprite.get_height())
        screen.blit(pygame.transform.scale(button.sprite , (w * scale , h * scale)) , ((button.pos)[0] * scale , (button.pos)[1] * scale))
    for item in itemDel:
        print(item)
        buttons.remove(item)
    del itemDel

I’ve had this issue before and had to entirely rewrite snippets of code. I have done this without ever knowing why this happens. Here I have no idea how to rewrite buttons and keys, as those are main components of the game. In the game loop (gameplay) it works as normal (output):

[<Assets.button.Button object at 0x000002112315BAF0>] [‘d’, ‘w’]

The Main Menu (not pause) doesn’t matter since no keyboard use is required. This only happens whenever the game is paused. I can luckily develop my game still, but it’ll be annoying if I accidently pause (which doesn’t really happen). I have no idea what is wrong with the code, I need help.

New contributor

MonkeyFeet10 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật