tkinter中的消息不起作用?

时间:2018-03-01 16:10:06

标签: tkinter

我的代码中发生了奇怪的事情。它说我的消息框(以及任何其他人,就此而言)是完全错误的。我把它插入另一段代码,它工作正常,但在这个文件中由于某种原因它不起作用。这就是我到目前为止所拥有的:

from Tkinter import *
import Tkinter
from winsound import *

root = Tkinter.Tk()

root.wm_title('Start - Minecraft Simulator Story Mode Deluxe')

Name = raw_input("Please enter your username. --> ")

def Testchange():
    root.wm_title('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')

def Start(Name):
    Combine = (Name,"has joined the game.")
    messagea.config(text=Combine)
    messageb.config(text="You log into a strange enough world.  You somehow know 3 possibilities of actions.")
    messagec.config(text="What would you like to do?")
    messaged.config(text="")
    buttona.config(text="Punch tree",command=Startfail1(Name))
    buttonb.config(text="Explore")
    buttonc.config(text="Go AFK")
def Startfail1(Name):
    messagea.config(text="")
    messageb.config(text="")
    messagec.config(text="")
    messaged.config(text="")
    buttona.config(text="Respawn",state="active",command=Start(Name))
    buttonb.config(text="",state="disabled",)
    buttonc.config(text="Main Menu",state="active",command=Start(raw_input("Please enter your username. --> "))    
messagea = Tkinter.Label(root, font="terminal", relief = "ridge", text="Line1")
messagea.grid(column=1, row=0, sticky=Tkinter.N)

messageb = Tkinter.Label(root,font="terminal",relief = "ridge", text="Line2")
messageb.grid(column=1, row=1, sticky=Tkinter.N)

messagec = Tkinter.Label(root,font="terminal",relief = "ridge", text="Line3")
messagec.grid(column=1, row=2, sticky=Tkinter.N)

messaged = Tkinter.Label(root,font="terminal",relief = "ridge", text="Line4")
messaged.grid(column=1, row=3, sticky=Tkinter.N)

buttona = Tkinter.Button(root, text="ButtonA", font="Monotxt", 
command=Testchange)
buttona.grid(row=4, column=0)

buttonb = Tkinter.Button(root, text="ButtonB", font="Monotxt", command=Testchange)
buttonb.grid(row=4, column=1)

buttonc = Tkinter.Button(root, text="ButtonC", font="Monotxt", 
command=Testchange)
buttonc.grid(row=5, column=2)
Start(Name)

root.iconbitmap('H:\Software\snaaaaake\depixelizer_1497134236479.ico')
root.mainloop()

它没有意义,我找不到它不起作用的原因。我失踪了什么?

以下是错误:

%run "H:/Software/snaaaaake/Minecraft Simulator Story Mode Deluxe.py"
  File "H:\Software\snaaaaake\Minecraft Simulator Story Mode Deluxe.py", line 39
messagea = Tkinter.Label(root, font="terminal", relief = "ridge", text="Line1")
       ^
SyntaxError: invalid syntax 

1 个答案:

答案 0 :(得分:0)

你在startfail1的最后一行犯了一个错误,使用打开的3个括号,但是你只关闭了2.因此,只需用以下代码替换该行:

B3.config(text="Main Menu",state="active",command=Start(input("Please enter your username. --> ")))