0

I apologize for my terrible English for I am not a native Englisgh speaker. As suggested in the title, the problem I had enncountered was that while I was embedding a pygame screen into a tkinter root using:

os.environ['SDL_WINDOWID'] = str(embeded_tk_window.winfo_id())
os.environ['SDL_VIDEODRIVER'] = 'windib'

and updating the screen in a loop like this:

while(True):
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            quit()
        if event.type==pygame.KEYDOWN:
            if event.key==pygame.K_SPACE:
                map0.check_all_value()
            if event.key==pygame.K_q:
                mode = "interect"
            if event.key==pygame.K_e:
                mode = "build" 
        if event.type == pygame.MOUSEWHEEL:
            map0.get_mouse_pos()
            if (event.y==1 or key[pygame.K_UP]) and zoom+0.1<=10:
                zoriginal_pos = (map0.mmx,map0.mmy)
                zoriginal_pos0 = (map0.mx,map0.my)
                zoom+=0.1
                map0.get_mouse_pos()
                view_point[0] = zoriginal_pos[0]-zoriginal_pos0[0]/zoom
                view_point[1] = zoriginal_pos[1]-zoriginal_pos0[1]/zoom
                
                
            elif (event.y==-1 or key[pygame.K_DOWN]) and zoom-0.1>=0.05:

                zoriginal_pos = (map0.mmx,map0.mmy)
                zoriginal_pos0 = (map0.mx,map0.my)
                zoom-=0.1
                map0.get_mouse_pos()
                view_point[0] = zoriginal_pos[0]-zoriginal_pos0[0]/zoom
                view_point[1] = zoriginal_pos[1]-zoriginal_pos0[1]/zoom
                
    if key[pygame.K_w]:
        view_point[1]-=speed*(zoom**-1.5)
    if key[pygame.K_s]:
        view_point[1]+=speed*(zoom**-1.5)
    if key[pygame.K_a]:
        view_point[0]-=speed*(zoom**-1.5)
    if key[pygame.K_d]:
        view_point[0]+=speed*(zoom**-1.5)
        
    if pygame.mouse.get_pressed()[1]:
        mouse_pos.append(pygame.mouse.get_pos())
        original_pos.append([view_point[0],view_point[1]])
        view_point[0]=-(mouse_pos[len(mouse_pos)-1][0]-mouse_pos[0][0])*(zoom**-1.5)+original_pos[0][0]
        view_point[1]=-(mouse_pos[len(mouse_pos)-1][1]-mouse_pos[0][1])*(zoom**-1.5)+original_pos[0][1]
    else:
        mouse_pos=[]
        original_pos=[]
    #do somethings here

    pygame.display.update()
    root.update()

    
    
    clock.tick(60)


The program cannot handle any keyboard input. However the mouse events are completely fine. I was wondering if there is a way I could fix this?

I sincerely thank you for your response.

4
  • In the application loop kye = pygame.mouse.get_pressed() is missing Commented Feb 10, 2024 at 11:07
  • I didn’t copy the correct part of the code. In the original code, that line is above the for loop Commented Feb 10, 2024 at 11:22
  • If the line is above the loop, that's just wrong. Commented Feb 10, 2024 at 11:52
  • I mean no offense sir/ma’am. I apologize if my words sounds offensive. And thank you. Commented Feb 10, 2024 at 12:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.