小编Owe*_*683的帖子

将按键调度到嵌入式Pygame

我一直在创建一些我将来可以使用的代码,以便在tkinter窗口中嵌入一个pygame窗口,以便使用tkinter菜单和按钮.我目前在处理按键时遇到了一些问题.我希望所有按键都由pygame而不是tkinter处理,这样如果pygame元素全屏显示(因此意味着不使用tkinter),那么tkinter键绑定将被忽略.

我的问题是,当窗口最初打开时(或者在它被单击并再次打开之后),只有tkinter正在注册键绑定.一旦用户点击了pygame窗口,只有pygame会注册键绑定.我的问题是如何检测tkinter或pygame是否正在检测按键,以及如何在检测到时使用pygame检测按下而不是tkinter?

我的代码在下面(对不起,它很长)

import pygame, os, _tkinter, sys
try:
    import Tkinter as tk
    BOTH,LEFT,RIGHT,TOP,BOTTOM,X,Y = tk.BOTH,tk.LEFT,tk.RIGHT,tk.TOP,tk.BOTTOM,tk.X,tk.Y
    two = True
except ImportError:
    import tkinter as tk
    from tkinter.constants import *
    two = False
from pygame.locals import *

class PygameWindow(tk.Frame):
    """ Object for creating a pygame window embedded within a tkinter window.

        Please note: Because pygame only supports a single window, if more than one
        instance of this class is created then updating the screen on one will update
        all of the …
Run Code Online (Sandbox Code Playgroud)

python pygame tkinter keypress python-3.x

8
推荐指数
1
解决办法
129
查看次数

跨越numpy矩阵的映射函数

有没有办法轻松地将函数映射到 numpy 数组中的每个值?我之前通过将其拆分为列表,使用列表理解并重新制作矩阵来完成它,但似乎必须有一种更简单的方法。

python numpy python-3.x

3
推荐指数
1
解决办法
9326
查看次数

标签 统计

python ×2

python-3.x ×2

keypress ×1

numpy ×1

pygame ×1

tkinter ×1