Tkinter notes

From OriWiki

Jump to: navigation, search

Contents

menu bar

import Tkinter 
 
root = Tkinter.Tk() 
 
canvas = Tkinter.Canvas(root, width=400, height=200, bg='white')
canvas.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
 
menubar = Tkinter.Menu(root)
 
filemenu = Tkinter.Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command=root.quit)
 
menubar.add_cascade(label="File", menu=filemenu)
 
root.config(menu=menubar)
 
root.mainloop()

trace a change of a value in a textarea

trace matrix change

 
  self.entry00text.trace_variable('w',self.refreshFutures)
---
  def refreshFutures(self,d1,d2,d3):
      if self.areFuturesVisable.get():
          self.refresh()
---
  self.entry00text = Tkinter.StringVar()
  self.entry00 = Tkinter.Entry(matrixPanel, textvariable=self.entry00text)
  self.entry00.grid(row=0,column=0)

window title and icon

root = Tkinter.Tk()
root.title("Linear transformer")
root.iconbitmap('ori.ico')

Key bindings

root = Tkinter.Tk()
root.bind('<a>', foo) # 'a' key 
root.bind('<Key>', foo) # any key
Personal tools