I'm new to Python, and now I'm trying to make a simple GUI with Tkinter.
So.. I want to change a button's color based on if file is selected clause:
Expand|Select|Wrap|Line Numbers
- import Tkinter, tkFileDialog, Tkconstants
- from Tkinter import *
- version = '1.0'
- filetext= 'Select Landsat 8 OLI'
- def openFile():
- filename = tkFileDialog.askopenfilename(parent=root,initialdir='/home/',title=filetext ,filetypes=[('ERDAS IMAGINE', '.img')]) ## filename not filehandle
- filebut["text"]= str(filename) if filename else filetext
- root = Tk()
- root.title('NDVI GUI ' + version)
- root.geometry('300x100')
- #Options for buttons
- button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5}
- #Define asking watermark file button
- filebut = Button(root, text = filetext, fg = 'black', command= openFile)
- filebut
- filebut.pack(**button_opt)
- root.mainloop()
Expand|Select|Wrap|Line Numbers
- filebut = Button
Expand|Select|Wrap|Line Numbers
- openFile
Expand|Select|Wrap|Line Numbers
- if filename else filetext
bg = "green"
else pass
I know that I probably this is very bad written but just wanted to see if could be done. Thank you!