[Tutor] Entry box + browse button

Klas Marteleur klas.martelleur at telia.com
Sat Aug 14 23:10:19 CEST 2004


I dont know what to try actually. 

Some idea i had was to call a function from the "command" in 
self.inputBrowseButton (self.openFile) and change the value of self.infile in 
that function. But i am not so sure about that idea anymore.

Some other idea i had was to "bind"  a button the "inputEntry" but i have no 
idea how to do that, i am just fumbling in the dark....

I could really need some guidance :)

Here is how my gui program loos at the moment

#!/usr/bin/python
from Tkinter import *

class CreateEbom(Frame):
    def __init__(self, master):
        self.myMaster = master
        self.myMaster.title('Tragic Converter BETA 0.1')
        self.myContainer1 = Grid()

        self.inputFile = Label(master, text="Input file:")
        self.inputFile.grid(row=0, sticky=E)
        
        self.outputFile = Label(master,text="Output file:")
        self.outputFile.grid(row=1, sticky=E)

        self.infile = 
"/home/klas/Python_filer/Tragic/ebom_from_file_wider.txt"
        self.inputEntry = Entry(master)
        self.inputEntry.insert(INSERT,self.infile)
        self.inputEntry.grid(row=0,column=1)

        self.outfile = "/home/klas/Python_filer/Tragic/output.txt"
        self.outputEntry = Entry(master)
        self.outputEntry.insert(INSERT,self.outfile)
        self.outputEntry.grid(row=1,column=1)

        self.inputBrowseButton = Button(master, command = self.openFile)
        self.inputBrowseButton.configure(text = "Browse")
        self.inputBrowseButton.grid(row=0,column=2)

        self.outputBrowseButton = Button(master, command = self.callback)
        self.outputBrowseButton.configure(text = "Browse")
        self.outputBrowseButton.grid(row=1,column=2)

        self.latestRevisonLabel = Label(master,text="Latest rev:")
        self.latestRevisonLabel.grid(row=2, sticky=E)

        self.var = IntVar()
        self.latestRevisionCheckbutton = Checkbutton(master,variable=self.var, 
command=self.checkButton)
        self.latestRevisionCheckbutton.grid(row=2,column=1,sticky=W)

        self.convertButton = Button(master, command = self.doProcessFiles)
        self.convertButton.configure(text="Convert")
        self.convertButton.grid(row=3,column=1,sticky=E)

        self.exitButton = Button(master, command = self.doExit)
        self.exitButton.configure(text="Exit")
        self.exitButton.grid(row=3,column=2,sticky=E)

        self.designedByLabel = Label(master,text="This program is designed in 
Python by Klas Marteleur")
        self.designedByLabel.grid(row=4,column=0,columnspan=3,sticky=S)

    def callback(self):
        print "Called the callback!"

    def checkButton(self):
        print "Variable is", self.var.get()

    def openFile(self):
        import tkFileDialog
        infile=tkFileDialog.askopenfilename()

    def doProcessFiles(self):
        from createEbom import *
        inputFileName = self.inputEntry.get()
        outputFileName = self.outputEntry.get()
        latestRevision = self.var.get()
        processFiles(inputFileName,outputFileName,latestRevision)


    def doExit(self):
        import sys
        sys.exit()
        return   


print "\n"*100 # a simple way to clear the screen
print "Starting..."
root = Tk()
createebom = CreateEbom(root)
root.mainloop()
print "Shutdown in progress..."
print "Done!"



More information about the Tutor mailing list