第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何從命令 tkinter 中獲取價(jià)值

如何從命令 tkinter 中獲取價(jià)值

皈依舞 2021-10-19 15:07:07
這可能是一個(gè)新手問(wèn)題,但我在弄清楚如何從函數(shù)中獲取值以用作另一個(gè)函數(shù)的輸入時(shí)遇到問(wèn)題。我還想了解一些有關(guān)代碼組織的技巧。在此示例中,我試圖獲取要在函數(shù) processFile 中使用的 filePath 和 outPut Folder 路徑。謝謝代碼:    from tkinter import *from tkinter import ttkfrom tkinter.filedialog import askopenfilenamefrom tkinter.filedialog import askdirectoryimport PyPDF2from PyPDF2 import PdfFileWriter, PdfFileReaderversion = "v0.0.01"root = Tk()def window (main):    main.title("File Opener " + version)    width = main.winfo_width()    main.geometry('500x200')numero = str(1)def OpenFile():    fileName = askopenfilename(initialdir="C:/",                            filetypes =(("PDF File", "*.pdf"),("All Files","*.*")),                            title = "Select PDF File",                           )    labelName = Label(text="File Path: " + fileName)    labelName.pack()    print(fileName)    return fileNamedef outputFolder():                                         #Bug, label keeps adding paths    outPath = askdirectory()    labelName2 = Label(text="Output Folder: " + outPath)    labelName2.pack()    print(outPath)    return outPathdef processFile(inFile,outFolder):   ''' print(fileName) get input name and output variables    print(outPath)'''label = ttk.Label(root, text ="",foreground="black",font=("Helvetica", 16))label.pack()#Button Open-----------button1 = Button (text = "Open File", command = OpenFile)button1.pack()#Button Start---------buttonStart = Button (text = "Start Process", command = processFile)#give as parameter inputFile and linkbuttonStart.place(height=50, width=100)#Button Open-----------button3 = Button (text = "Output Folder", command = outputFolder)button3.pack()#Menu Bar ----------------menu = Menu(root)root.config(menu=menu)file = Menu(menu)file.add_command(label = 'Open', command = OpenFile)file.add_command(label = 'Exit', command = lambda:exit())menu.add_cascade(label = 'File', menu = file)window(root)root.mainloop()
查看完整描述

2 回答

?
慕桂英3389331

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊

如果您在變量中使用該函數(shù),則該函數(shù)的返回結(jié)果將存儲(chǔ)在該變量中。


def Function1(x):

    return x*2


var1 = Function1(5)

然后 var1 = 10。


但是關(guān)于您的按鈕,您是想從用戶(hù)那里獲取在按下按鈕時(shí)保存的輸入還是希望按鈕發(fā)送一個(gè)設(shè)定值?


查看完整回答
反對(duì) 回復(fù) 2021-10-19
?
狐的傳說(shuō)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊

from tkinter import *

from tkinter import ttk

from tkinter.filedialog import askopenfilename

from tkinter.filedialog import askdirectory

import PyPDF2

from PyPDF2 import PdfFileWriter, PdfFileReader


version = "v0.0.01"



root = Tk()





def window (main):


    main.title("File Opener " + version)

    width = main.winfo_width()

    main.geometry('500x200')

    main.configure(background = 'black')


numero = str(1)


#openFile

def OpenFile():

    global fileName

    fileName = askopenfilename(initialdir="C:/",

                            filetypes =(("PDF File", "*.pdf"),("All Files","*.*")),

                            title = "Select PDF File",

                           )


    labelName = Label(text="File Path: " + fileName)

    labelName.pack()

    print(fileName)

    return str(fileName)


#getOutputPath


def outputFolder():                                         #Bug, label keeps adding paths

    outPath = askdirectory()


    labelName2 = Label(text="Output Folder: " + outPath)

    labelName2.pack()

    print(outPath)

    return outPath


#testFunct


def printFilename(inArg):

    print(inArg)

    x = OpenFile()

    print (OpenFile())





lambda: printFilename(fileName)


#processRealDeal


def processFile(): #THIS IS THE MAIN FUNC


   ''' print(fileName) get input name and output variables

    print(outPath)'''



print (OpenFile)


label = ttk.Label(root, text ="",foreground="black",font=("Helvetica", 16))

label.pack()



#Button Open-----------


button1 = Button (text = "Open File", command = OpenFile)

button1.pack()



#Button Start---------

buttonStart = Button (text = "Start Process", command = lambda: printFilename("Hello World!!!"))#give as parameter inputFile and link

buttonStart.place(height=50, width=100)


#Button Open-----------


button3 = Button (text = "Output Folder", command = outputFolder)

button3.pack()



#Menu Bar ----------------


menu = Menu(root)

root.config(menu=menu)


file = Menu(menu)



file.add_command(label = 'Open', command = OpenFile)

file.add_command(label = 'Exit', command = lambda:exit())


menu.add_cascade(label = 'File', menu = file)



window(root)

root.mainloop()


查看完整回答
反對(duì) 回復(fù) 2021-10-19
  • 2 回答
  • 0 關(guān)注
  • 207 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)