Hi guys,
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:
I was wondering if I could change bg to green of the
based on the function
clause
Something like if filename == None:
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!
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:
Code:
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()
Code:
filebut = Button
Code:
openFile
Code:
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!
Comment