使用Tkinter Python从函数中获取值

时间:2018-06-10 02:44:46

标签: python methods tkinter return-value

我有两个文件PLC.py和fie.py. 我想通过返回方法从PLC.py中的file.py获取值,但我无法确定如何达到aux变量的值:

PLC.py部分代码:

from tkinter import filedialog
from tkinter import *
import  library.file as file
root = Tk()
root.state("zoomed")
# Code to add widgets will go here...
root.title("Interactive Toys")
menubar = Menu(root)
#File menu
#aux=StringVar()
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open",command=lambda:file.openfile(root))
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu = menubar)
root.mainloop()

file.py:

from tkinter import filedialog
from tkinter import messagebox
from tkinter import font  as tkfont
from tkinter import *
import os
def openfile(root):
    print('hello')
    root.filename =  filedialog.askopenfilename(initialdir = "/Libraries/Document",title = "Select file",filetypes = (("py files","*.py"),("all files","*.*")))
    print (root.filename)
    aux=root.filename
    aux2=root.filename.split('/')
    return aux

0 个答案:

没有答案