最近我正在学习tkinter,我想把1个代码分成2个代码,但是我总是发现错误
clicked = StringVar()
NameError: name 'StringVar' is not defined
或者我们如何在按下按钮后发送/捕获另一个文件?
home.py
from tkinter import *
from tkinter import ttk
from w2 import *
options =[
"cone",
"Ball",
"Cube",
"Beam"
]
clicked = StringVar()
clicked.set(options[0])
Label(win, text="Enter Number", font=('Calibri 10'), bg="yellow", fg="black").place(x=315, y=5)
drop = ttk.Combobox(win, width = 27, textvariable = clicked, value=options)
drop.place(x=265, y=35)
w2.py
def show():
for i in options:
if clicked.get() == 'cone':
myButton1['state'] = DISABLED
mylabel = Label(win, text="Volume Cone",bg="yellow", fg="black")
mylabel.place(x=315, y=125)
mylabels = Label(win, text="r : ",bg="yellow", fg="black")
mylabels.place(x=180, y=155)
mylabelq = Label(win, text="h : ",bg="yellow", fg="black")
mylabelq.place(x=350, y=155)
a=Entry(win, width=21)
a.place(x=200, y=155)
b=Entry(win, width=22)
b.place(x=375, y=155)
myDel2 = Button(win, text="CLEAR VOLUME CONE", command=myDel)
myDel2.place(x=200, y=178)
my_label2 = Label(height=89,width=259,image=my_img)
my_label2.place(x=225, y=238)
myButton23 = Button(win,width=18, text="calculate", command=cal_cone , bg="red", fg="white")
myButton23.place(x=375, y=178)
wlabel = Label(win, text="")
break
这是完整的代码
https://github.com/IMVERBILIUS/SIMPLE_VOLUME_CONE-BALL_GUI/blob/master/home.py
1条答案
按热度按时间k4emjkb11#
home.py
中.创建了一个名为show_w2()
的函数command=show_w2
添加参数w2.py
中,添加tkinter
库w2.py
中.创建了一个名为run()
的函数代码:
w2.py.
代码:
截图:
点击显示按钮后截图: