我正在使用Pygame模块制作一个简单的游戏。我需要在Pygame窗口旁边打开一个Tkinter窗口。
每当我尝试打开两个窗口时,第二个窗口仅在我杀死第一个窗口之后打开。
现在,我能想到的唯一解决方案是使用多线程。但是,我无法实现它。
我该如何处理? 我非常感谢您的帮助。 谢谢!
答案 0 :(得分:3)
在pygame中存在一个基本的设计问题,如果该进程已经有一个窗口,则它无法打开窗口。它还将阻止其他窗口在运行时打开。但是,您可以根据需要打开任意数量的TK窗口,也可以将pygame窗口嵌入TK窗口内的SDL绘图框架中。
有关如何使用并条机,请参见以下答案:Embedding a Pygame window into a Tkinter or WxPython frame
有关如何在// create the context with necessary keys
const FullScreenContext = createContext({
fullscreen: false
});
// consumer if you want to use it with nesting
export const FullScreenContextConsumer = FullScreenContext.Consumer;
// provider to provide it to the components
export const FullScreenContextProvider = ({ children }) => {
const [isFullScreen, setIsFullScreen] = useState(false);
const enableFullScreen = () => setIsFullScreen(true);
const disableFullScreen = () => setIsFullScreen(false);
return (
<FullScreenContext.Provider value={{fullscreen: isFullScreen}}>
{children}
</FullScreenContext.Provider>
);
}
export default FullScreenContext; // the default export, for `useContext(..)`
中创建多个窗口的信息,请参见以下答案:How to open multiple windows in Tkinter