我无法在我的tkinter屏幕上显示答案

时间:2017-10-06 17:32:49

标签: python tkinter

我使用tkinter制作转换器单元。我的代码显示错误,但屏幕上没有任何内容

# implement the variable
var1 = DoubleVar()
var2 = StringVar()
var3 = StringVar()

def conver():
              t1 = { "km": 1000,
                     "hm" : 100,
                     "dam": 10,
                      "m": 1,
                      "dm" : 0.1,
                      "cm": 0.01,
                      "mm" : 0.001   }


               t2 = { "kg": 1000,
                      "hg" : 100,
                      "dag": 10,
                      "g" : 1,
                      "dg" : 0.1,
                      "cg": 0.01,
                      "mmg": 0.001}




                 A = var1.get()
                 B = var1.get()
                 C = var3.get()
                 if B in t1.keys() and C in t1.keys():
                                B1 = t1[B]
                                C1 = t1[c]
                                N = A * (B1/C1)
                                text.insert(END, str(N))

                 Number = Entry( Left, bd = 10, text = var1)
                 Number.grid(row = 0)
                 Number1 = Entry( Left, bd = 10, text = var2)
                 Number1.grid(row = 0,column = 1)
                 Number2 = Label( Left, bd 
                 =10,tex"en",font("arial",10,"bold"))
                 Number2.grid(row = 0,column = 2)
                 Number3 = Entry( Left, bd = 10, text = var3)
                 Number3.grid(row = 0,column=3)
                 number4 = Button(Left,font = 
                 ("arial",10,"bold"),text = "Cacul",command = 
                 conver,bg = "SeaGreen1" ,bd = 10)
                 number4.grid(row =10 )

                 Right = Frame(root,bd =10)
                 Right.pack(side= RIGHT)
                 text = Text(Right, bd =10, width = 50, height = 
                 20)
                text.pack(side = RIGHT)

我试图将一个单位转换为特定单位(例如1km = 1000m),当我运行我的代码时,我在屏幕上看不到任何内容。我不知道我做错了什么。我把我的代码放了。谢谢!

1 个答案:

答案 0 :(得分:0)

您的语法Number2 = Label( Left, bd=10,tex"en",font("arial",10,"bold"))无效。通常当出现错误时,Tkinter会导致它无法显示。我猜您的意思是text="en"font=("arial",10,"bold"),因为字体不是函数而是关键字。