如何在另一个python脚本中使tkinter条目成为变量

时间:2019-02-13 17:14:56

标签: python tkinter python-os

我已经创建了2个脚本。

1。rec.py使用tkinter输入用户输入

2。classify.py使用来自rec.py的输入来执行转换

我想要实现的目标:

  1. rec.py调用用户输入,并使其在classify.py中成为变量

  2. 使用变量在classify.py

  3. 中执行转换
  4. 打印classify.py的输出

我做了什么:

rec.py

def click(text_user_example):
    text_user = text_user_example
    os.system("classify.py")

#create a text entry box
text_user = Entry(window, width=20, bg="white")
text_user.grid(row=2, column=0, sticky=W)

#add a submit button
Button(window, text="SUBMIT", width=6, command = lambda: 
click(text_user)).grid(row=3, column=0,  sticky=W)

classify.py

from rec import text_user #this is the only variable i want from "rec.py"
--other tranformations using text_user
print(text_user) 

不幸的是,每次我运行classify.py时,tkinter界面都会弹出,即使我已经提交了输入也是如此(输入文本用户后该界面不应弹出)。

我在做什么错了?

0 个答案:

没有答案