Hi I am trying my hand at GUI using Python and Tkinter. I know there are probably better options out there but I only have access to Tkinter here at work. My question is this. I have written this:
#!/usr/local/bin/python2.6
from Tkinter import *
import os
root = Tk()
root.title("EIMA validation tool")
root.geometry("450x300")
var = StringVar()
tdir = os.getcwd()
files_and_dirs = [file for file in os.listdir(tdir) if os.path.isdir(file)]
files_and_dirs.sort()
var.set(files_and_dirs[0])
the_menu = OptionMenu(root, var, *files_and_dirs)
the_menu.grid(row = 0, column=0)
root.mainloop()
At the moment this doesn't do much but at least it's starting to look like something. In this case files_and_dirs
is a list of directories which is used to populate my OptionMenu
this works great. But now I'm trying to turn this into a "proper" script :
#!/usr/local/bin/python2.6
from Tkinter import *
import ttk
import os
class IEMA(object):
def __init__(self, m_window):
m_window.title('IEMA validation app')
m_window.geometry('250x250')
self.left_frame = ttk.Frame(m_window)
self.left_frame.grid()
self.var = StringVar()
self.tdir = os.getcwd()
self.files_and_dirs = ListType()
self.files_and_dirs = [file for file in os.listdir(self.tdir) if os.path.isdir(file) or file.endswith(('xml', 'XML'))]
self.files_and_dirs.sort()
self.var.set(self.files_and_dirs[0])
self.the_menu = OptionMenu(self.left_frame, self.var, self.files_and_dirs)
self.the_menu.grid(row=0, column=0)
if __name__ == '__main__':
root = Tk()
iema_app = IEMA(root)
root.mainloop()
This, *files_and_dirs
, results in an Invalid Syntax error and just using self.files_and_dirs
does not work. So far Google hasn't helped. Does anyone know how to fix this?