prompt: Can you show me how to list files in a GUI window using python?
chosen.role: system
chosen.content: A chat.
chosen.role: user
chosen.content: Can you show me how to list files in a GUI window using python?
chosen.role: assistant
chosen.content: Of course! We'll use Python's Tkinter module as well as the Tkinter.ttk widget set like so:
  
  import os
  import tkinter as tk
  from tkinter import ttk
  
  root = tk.Tk()
  
  # create a treeview widget
  tree = ttk.Treeview(root)
  tree.pack(fill=tk.BOTH, expand=1)
  
  # add columns to treeview
  tree['columns'] = ('size', 'modified')
  tree.column('#0', width=200, minwidth=50, anchor='w')
  tree.column('size', width=100, minwidth=50, anchor='center')
  tree.column('modified', width=150, minwidth=50, anchor='center')
  
  # set column headings
  tree.heading('#0', text='Name', anchor='w')
  tree.heading('size', text='Size', anchor='center')
  tree.heading('modified', text='Modified', anchor='center')
  
  # list of all files and directories
  files = os.listdir('./')
  
  # add files to treeview
  for file in files:
      # get path
      path = os.path.join('./', file)
      # get file size
      size = os.path.getsize(path)
      # get last modfied
      modified = os.path.getmtime(path)
      # add item to treeview
      tree.insert('', 'end', text=file, values=(size, modified))
  
  # main loop
  root.mainloop()
rejected.role: system
rejected.content: A chat.
rejected.role: user
rejected.content: Can you show me how to list files in a GUI window using python?
rejected.role: assistant