当我运行脚本时,它会自动运行秒脚本。我试图让它成为一个标题屏幕,您可以通过单击开始按钮开始游戏,但当我运行程序时,它会自动启动第二个程序。它不会用我的其他按钮来执行此操作,所以我不确定问题是什么。
代码在下面
from tkinter import *
import other_modules.Main
#Define Background Main Screen Color
root = Tk()
root.title("Root")
root.configure(background= "deep sky blue")
root.minsize(800, 500) # width, height
root.maxsize(1200, 700)
root.geometry("300x300+50+50")
root.grid_rowconfigure(5, weight=1)
root.grid_columnconfigure(0, weight=1)
#Background Colors Commands!!!
def BgLBlue():
root.configure(background = "deep sky blue")
Title = Label(root, text="Game", font=("Ariel",45), bg="deep sky blue")
Title.grid(row=1, padx=55, pady=30)
def BgRed():
root.configure(background = "Red")
Title = Label(root, text="Game", font=("Ariel",45), bg="Red")
Title.grid(row=1, padx=55, pady=30)
def BgGreen():
root.configure(background = "Green")
Title = Label(root, text="Game", font=("Ariel",45), bg="Green")
Title.grid(row=1, padx=55, pady=30)
#Commands
def ColorMenu():
#Colors Menu
Color = Tk()
Color.title("Color")
Color.configure(background="saddle brown")
Color.minsize(400, 250) # width, height
Color.maxsize(1200, 700)
Color.geometry("100x100+500+500")
Color.grid_rowconfigure(5, weight=1)
Color.grid_columnconfigure(0, weight=1)
#Colors Buttons
Lblue = Button(Color, bg = "deep sky blue", text=" ", command = BgLBlue)
Lblue.grid(row=1, column=0, padx=5, pady=5)
Red = Button(Color, bg = "red", text=" ", command = BgRed)
Red.grid(row=2, column=0, padx=5, pady=5)
Green = Button(Color, bg = "SpringGreen2", text=" ", command = BgGreen)
Green.grid(row=3, column=0, padx=5, pady=5)
def Startgame():
other_modules.Main
def Optionsmenu():
#Menu Screen
options = Tk()
options.title("options")
options.configure(background="snow")
options.minsize(400, 250) # width, height
options.maxsize(1200, 700)
options.geometry("100x100+500+500")
options.grid_rowconfigure(5, weight=1)
options.grid_columnconfigure(0, weight=1)
#Options Buttons
BgColor = Button(options, text ="Colors!", command = ColorMenu, font=("Ariel",11), bg = "gray82")
BgColor.grid(row=3, padx=55, pady=30)
def QuitCom():
root.quit()
#Options Menu
##Background Color
#Title
Title = Label(root, text="Game", font=("Ariel",45), bg="deep sky blue")
Title.grid(row=1, padx=55, pady=30)
#BUTTONS DO NOT MESS THEM UP!!!
Start = Button(root, text ="Start", command = Startgame, font=("Ariel",11), bg = "gray82")
Start.grid(row=2, padx=55, pady=30,)
#
Options = Button(root, text ="Options", command = Optionsmenu, font=("Ariel",11), bg = "gray82")
Options.grid(row=3, padx=55, pady=30)
#
Quitgame = Button(root, text ="Quit", command = QuitCom, font=("Ariel",11), bg = "gray82")
Quitgame.grid(row=4, padx=55, pady=30)
root.mainloop()
字符串
Startgame()是问题所在一旦我运行了这个脚本,其他模块.Main就会运行。我希望它只在单击开始按钮时启动。
1条答案
按热度按时间t98cgbkg1#
你需要实际执行该模块中的代码。将
Startgame
函数改为:字符串
确保
other_modules
目录与主脚本在同一目录中