[英]Tkinter: Using entry value in another file
When file1.py runs and the submit button is hit, the submit method will return entry.get() value, which is fine. 运行file1.py并单击“提交”按钮时,submit方法将返回entry.get()值,这很好。 However, if I wanted too transfer the entry.get() too another python file when the submit button is hit.
但是,如果我也想在单击“提交”按钮时将entry.get()也转移到另一个python文件中。 Is this possible?
这可能吗?
file1.py file1.py
from tkinter import *
root = Tk()
def submit():
return entry.get()
entry = Entry(root)
entry.pack()
submit_button = Button(root, text = "Submit", command = submit)
submit_button.pack()
root.mainloop()
file2.py file2.py
import file1 as f1
from tkinter import messagebox
var = submit()
if var == "test":
messagebox.showinfo("Hello")
This is what I'm wanting to do but having no luck with it atm. 这是我想要做的,但是atm没有运气。
You can pass the value to a function that you have defined in the other file like this. 您可以像这样将值传递给在其他文件中定义的函数。
p1.py p1.py
from tkinter import *
from p2 import new_print
root = Tk()
def submit():
new_print(entry.get())
entry = Entry(root)
entry.pack()
submit_button = Button(root, text = "Submit", command = submit)
submit_button.pack()
root.mainloop()
p2.py p2.py
value_from_p1 = None
def new_print(value):
global value_from_p1
value_from_p1 = value
print(value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.