我無法從「Entry」中檢索變量,然後將該變量輸入到函數中。例如,我想檢索一個變量「entry」的「NbF」。我在「設置」,我可以檢索它與「獲取」,但當我得到一個新的文本「條目」,我沒有得到新的價值。Python - Tkinter - 我想從函數獲取()的值從函數中使用
這是我的代碼:
#!/usr/local/bin/python
# -*- coding:utf-8 -*-
from Tkinter import *
import tkFileDialog, tkMessageBox
application = Tk()
application.title("Application Drone - Analyse Vidéo")
def getFile():
varName = tkFileDialog.askopenfilename().encode('utf-8')
Name.set('Path : ' + varName)
def convert(nbFrame):
print 'ffmpeg -i pathVideo -r '+nbFrame+' -f image2 "temp%4d.png"'
def detect():
pass
def analyse():
pass
frame1 = Frame(application, bg="blue", width=560, height=100)
frame1.pack(side=TOP, fill=X)
frame2 = Frame(application, bg="red", width=560, height=100)
frame2.pack(side=TOP, fill=X)
frame3 = Frame(application, bg="green", width=560, height=100)
frame3.pack(side=TOP, fill=X)
frame4 = Frame(application, bg="yellow", width=560, height=100)
frame4.pack(side=TOP, fill=X)
frame5 = Frame(application, bg="grey", width=560, height=100)
frame5.pack(side=BOTTOM, fill=BOTH, expand=1)
#frame 1
Name=StringVar()
lab1 = Label(frame1, text="Step 1 : Recup video").grid(row=0,column=0)
butt1 = Button(frame1,text="browse",command=getFile).grid(row=0,column=1)
nameVideo = Label(frame1, textvariable=Name).grid(row=1,column=0)
#frame 2
NbF = StringVar()
NbPictures=StringVar()
lab2 = Label(frame2, text="Step 2 : Convert video to images").grid(row=0,column=0)
ent2 = Entry(frame2, textvariable=NbF).grid(row=0,column=1)
# ent2.pack()
NbF.set('nb frame')
recup2 = NbF.get()
butt2 = Button(frame2,text="convert",command=lambda :convert(recup2)).grid(row=0,column=2)
nbP = Label(frame2, textvariable=NbPictures).grid(row=1,column=0)
#frame 3
NbS=StringVar()
lab3 = Label(frame3, text="Step 3 : Detect shape").grid(row=0,column=0)
butt3 = Button(frame3,text="detect",command=lambda :detect).grid(row=0,column=1)
numberShape = Label(frame3, textvariable=NbS).grid(row=1,column=0)
#frame 4
NbC=StringVar()
lab4 = Label(frame4, text="Step 4 : Analyse QrCode").grid(row=0,column=0)
butt4 = Button(frame4,text="analyse",command=lambda :analyse).grid(row=0,column=1)
numberCoord = Label(frame4, textvariable=NbC).grid(row=1,column=0)
#frame 5
lab5 = Label(frame5, text="Step 5 : Send coordonates").grid(row=0,column=0)
butt5 = Button(frame5,text="send",command=lambda :send).grid(row=0,column=1)
application.mainloop()
我很難理解問題出在哪裏。有幾件事情可能會導致問題,但'.grid'方法總是返回'None'。在你的代碼中,當你懷疑你期望的時候,你會給很多變量分配'None'。 – mgilson