|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想将以下代码mian函数中的那一坨代码放到win_tk()函数中去该怎么改啊,
如果直接放进去的话run_com()函数中etyText.get()就没办法获取到entry中的内容
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import *
def win_tk():
pass
def select_com():
etyText.set(askopenfilename())
def run_com():
filePath = etyText.get()
showinfo('Tips', filePath)
if __name__ == '__main__':
root = tk.Tk()
root.attributes('-alpha', 0.9)
root.geometry('700x200+400+200')
etyText = tk.StringVar()
lb = tk.Label(root, font=('Arial', 10), text=' File Path :')
ety = tk.Entry(root, font=('Arial', 10), textvariable=etyText, width=80)
btnSelect = tk.Button(root, font=('Arial', 10), text=' Select ', command=select_com)
btnRun = tk.Button(root, font=('Arial', 10), fg='white', bg='gray', text=' Run ', command=run_com)
lb.grid(row=0, column=0)
ety.grid(row=0, column=1)
btnSelect.grid(row=0, column=2)
btnRun.grid(row=1, column=1)
tk.mainloop()
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import *
def win_tk():
root = tk.Tk()
root.attributes('-alpha', 0.9)
root.geometry('700x200+400+200')
etyText = tk.StringVar()
lb = tk.Label(root, font=('Arial', 10), text=' File Path :')
ety = tk.Entry(root, font=('Arial', 10), textvariable=etyText, width=80)
btnSelect = tk.Button(root, font=('Arial', 10), text=' Select ', command=select_com)
btnRun = tk.Button(root, font=('Arial', 10), fg='white', bg='gray', text=' Run ', command=run_com)
lb.grid(row=0, column=0)
ety.grid(row=0, column=1)
btnSelect.grid(row=0, column=2)
btnRun.grid(row=1, column=1)
tk.mainloop()
def select_com():
etyText.set(askopenfilename())
def run_com():
filePath = etyText.get()
showinfo('Tips', filePath)
if __name__ == '__main__':
win_tk()
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import *
def select_com():
etyText . set(askopenfilename())
def run_com():
filePath = etyText.get()
showinfo('Tips', filePath)
def win_tk():
global etyText # 添加此句,把 etyText 置为全局变量
root = tk.Tk()
root.attributes('-alpha', 0.9)
root.geometry('700x200+400+200')
etyText = tk.StringVar()
lb = tk.Label(root, font=('Arial', 10), text=' File Path :')
ety = tk.Entry(root, font=('Arial', 10), textvariable=etyText, width=80)
btnSelect = tk.Button(root, font=('Arial', 10), text=' Select ', command=select_com)
btnRun = tk.Button(root, font=('Arial', 10), fg='white', bg='gray', text=' Run ', command=run_com)
lb.grid(row=0, column=0)
ety.grid(row=0, column=1)
btnSelect.grid(row=0, column=2)
btnRun.grid(row=1, column=1)
tk.mainloop()
if __name__ == '__main__':
win_tk()
|
|