好的,所以我并不完全了解游戏开发。
所以,我一直在打开一个窗口(我已经这样做了),这个窗口将在我需要时显示不同的框架。
下面的代码打开窗口并打开框架:
from StartGame import Start_gameFrameTest
from tkinter import *
from PIL import ImageTk
from PIL import Image
def Game_window():
window=Tk()
window.title("C&D:FourSwords")
window_width=window.winfo_screenwidth()
window_height=window.winfo_screenheight()
print(window_height,window_width)
window.geometry("%dx%d+%d+%d"%(window_width,window_height,0,0))
window.resizable(width=True, height=True)
Menu=Start_gameFrameTest.Start_game(window_width,window_height)
Game_window()
然后它打开的是这个框架,它是在标签内显示一个按钮:
from tkinter import *
from PIL import ImageTk
from PIL import Image
class Start_game(Frame):
def __init__(game,window_width,window_height):
game.window=super().__init__()
game.background(window_width,window_height)
game.Buttons(window_width,window_height)
game.window.mainloop()
def background(game,window_width,window_height):
game.window_width=window_width
game.window_height=window_width
game.file=open("directory.txt")
game.name=game.file.read()
game.photobg=Image.open(game.name)
game.photobg=game.photobg.resize((window_width,window_height))
game.imbg=ImageTk.PhotoImage(game.photobg)
game.label=Label(game.window,image=game.imbg)
game.label.image=game.imbg
game.label.pack()
def Buttons(game,window_width,window_height):
game.button_start=Button(game)
game.photoB=Image.open(game.name)
game.photoB=game.photoB.resize((100,200))
game.imgb=ImageTk.PhotoImage(game.photoB)
game.button_start.config(image=game.imgb)
game.button_start.image=game.imgb
game.button_start.place(game.window,in_=game.label, x=((window_width)/2),y=((window_height)/2))
这当然只是一个测试样本,但有同样的问题,这里也是错误代码:
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 输入“help”、“copyright”、“credits”或“license( )“ 了解更多信息。
重新启动:D:\Create and Destroy\FourSwords\Create_And_Destroy_Four_Swords.py Traceback(最近一次调用最后一次):文件“D:\Create and Destroy\FourSwords\Create_And_Destroy_Four_Swords.py”,第 14 行,在 Game_window() 文件“D:\ Create and Destroy\FourSwords\Create_And_Destroy_Four_Swords.py",第 13 行,在 Game_window
Menu=Start_gameFrameTest.Start_game(window_width,window_height) 文件 "D:\Create and Destroy\FourSwords\StartGame\Start_gameFrameTest.py",
第 8 行,在初始化 游戏中.Buttons(window_width,window_height) 文件“D:\Create and Destroy\FourSwords\StartGame\Start_gameFrameTest.py”,
第 34 行,在 Buttons
game.button_start.place(game.window,in_=game.label, x=((window_width)/2),y=((window_height)/2))File"C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2188, in place_configure + self._options(cnf, kw))
_tkinter.TclError: 不能相对于 .!label 放置 .!start_game.!button
请不要做这个网站所做的事情,只是给哦你应该使用它然后走开,请解释我应该如何以及为什么要使用它。
对于没有时间尝试和错误您模糊答案的我来说,这很烦人。因为如果我能做到那我就不会在这里了。