【发布时间】:2015-07-24 15:05:13
【问题描述】:
当我尝试使用 tkinter 创建转换程序时,我在解析时收到错误 EOF。这是我的代码:
from tkinter import *
from tkinter.ttk import *
class conversion:
def centi():
def centiMet():
meStr=a.get()
meStrc = eval(meStr)
con=meStrc/100
conS=str(con)
CenMet2=Label(root,text=conS + " Meters",font="CenturyGothic 12 bold").pack()
return
rootCm= Tk()
a = StringVar()
rootCm.geometry("500x300")
rootCm.title("Quick Reference Application - Version 0.1.8 [alpha] ")
label1= Label(rootCm,text="Unit Conversions",font="CenturyGothic 17 bold").pack()
inputCm= Entry(rootCm,textvariable=a).pack()
convButton1= Button(rootCm,text="Convert!",command = centiMet).pack()
root= Tk()
root.geometry("500x300")
root.title("Quick Reference Application - Version 0.1.8 [alpha] ")
label1= Label(root,text="Unit Conversions",font="CenturyGothic 17 bold").pack()
CenMet1= Label(root,text="Please select the type you want!!",font="CenturyGothic 12 bold").pack()
convButton1= Button(root,text="Centimeters to Meters",command = conversion.centi).pack()
单击厘米到米按钮并尝试转换后,将显示错误。在我尝试制作一个按钮以启动一个厘米到米的新窗口之前,它工作正常。有人有什么建议吗?
【问题讨论】:
-
一个 tkinter GUI 不应该有两个
Tk实例。如果您需要更多窗口,请使用Toplevel的实例。
标签: python python-3.x tkinter ttk