|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
root=Tk()
Label(root,text="分类数:").grid(row=0,column=0)
Label(root,text="依次输入几个分类高斯分布均值,方差:").grid(row=1,column=0)
v1=StringVar()
v2=StringVar()
e1=Entry(root,textvariable=v1)
e2=Entry(root,textvariable=v2)
e1.grid(row=0,column=1,padx=5,pady=5)
e2.grid(row=1,column=1,padx=5,pady=5)
global num
global variables
def get_variables():
num= e1.get() #获取文本框内容
variables = e2.get()
print(num)
print(variables)
Button(root,text="确认",width=10,command= get_variables)\
.grid(row=2,column=2,sticky=W,padx=10,pady=10)
Button(root,text="退出",width=10,command=root.quit)\
.grid(row=3,column=2,sticky=E,padx=10,pady=10)
print(num)
print(variables)
mainloop()
通过组件来打印 num 和 variables 的值(输入后需要先按确定,使得 num、variables 赋值),参考代码:
from tkinter import *
root = Tk()
Label(root, text="分类数:").grid(row=0, column=0)
Label(root, text="依次输入几个分类高斯分布均值,方差:").grid(row=1, column=0)
v1 = StringVar()
v2 = StringVar()
e1 = Entry(root, textvariable=v1)
e2 = Entry(root, textvariable=v2)
e1.grid(row=0, column=1, padx=5, pady=5)
e2.grid(row=1, column=1, padx=5, pady=5)
num,variables = None,None
def get_variables():
global num,variables
num = e1.get() # 获取文本框内容
variables = e2.get()
Button(root, text="确认", width=10, command=get_variables) \
.grid(row=2, column=2, sticky=W, padx=10, pady=10)
Button(root, text="退出", width=10, command=root.quit) \
.grid(row=3, column=2, sticky=E, padx=10, pady=10)
def print_value():
print(num)
print(variables)
Button(root, text="打印", width=10, command=print_value) \
.grid(row=2, column=1, sticky=E, padx=10, pady=10)
mainloop()
|
|