Advertisement
diliupg

Easy scales and chords

Oct 22nd, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.51 KB | None | 0 0
  1. ## Find notes in scales and chords simply by giving the name of the scale
  2.  
  3. import Tkinter
  4. from Tkinter import LEFT
  5. import scale_arp_chords_data as data
  6. import give_scales_chord_names as helper
  7. import getinim
  8.  
  9. class userinterface_tk(Tkinter.Tk):
  10.     def __init__(self,parent):
  11.         Tkinter.Tk.__init__(self,parent)
  12.         self.parent = parent
  13.         self.initialize()
  14.  
  15.  
  16.     def initialize(self):
  17.         self.grid()
  18.         self.mode = "Scale Mode"
  19.  
  20.         ## print the user guide top level
  21.         self.WhichUserGuide = Tkinter.StringVar()  # variable text
  22.         self.temp = self.WhichUserGuide
  23.         self.guide_label = Tkinter.Label(self, justify=LEFT, textvar = self.WhichUserGuide, anchor = "w", fg = "black", bg = "lightblue", font = "Calibri 14", border = 20)
  24.         self.guide_label.grid(row = 0, column = 0, columnspan = 4, sticky = 'NW')
  25.         self.WhichUserGuide.set(data.scaleguide)
  26.  
  27.  
  28.         ## make toggle button to select scales or chords
  29.         self.ScaleChordVar = Tkinter.StringVar()
  30.         self.Togglebutton = Tkinter.Button(self, textvar = self.ScaleChordVar, height = 1, width = 11, font = "Calibri 12 bold", fg = "blue", bg = "lightgrey", border = 4, command = self.toggle)
  31.         self.Togglebutton.grid(row= 3, sticky = 'W')
  32.         self.ScaleChordVar.set('Scale Mode')
  33.  
  34.  
  35.         ## make the user scale/chord request box
  36.         self.entryVariable = Tkinter.StringVar()
  37.         self.entry = Tkinter.Entry(self,textvariable = self.entryVariable, font = "Calibri 12")
  38.         self.entry.grid(column = 0, row = 1, sticky = 'EW')
  39.         self.entry.bind("<Return>", self.OnPressEnter)
  40.         self.entryVariable.set(u"Scale or chord..")
  41.  
  42.  
  43.         ## make the answer box which starts with Your answer will be..... but will hold last answer
  44.         self.labelVariable = Tkinter.StringVar()
  45.         label = Tkinter.Label(self,textvariable = self.labelVariable,
  46.                               anchor = "w", fg = "white", bg = "blue", font = "Calibri 12")
  47.         label.grid(column = 0, row = 2, columnspan = 2, sticky = 'EW')
  48.         self.labelVariable.set(u"Your answer will be displayed here..")
  49.  
  50.  
  51.         self.grid_columnconfigure(0,weight = 1)
  52.         self.resizable(False, False)
  53.         self.update()
  54.         self.geometry(self.geometry())
  55.         self.entry.focus_set()
  56.         self.entry.selection_range(0, Tkinter.END)
  57.  
  58.  
  59.     def toggle(self):
  60.  
  61.         if self.ScaleChordVar .get().title() == ("Scale Mode"):
  62.             self.mode = "Chord Mode"
  63.             self.WhichUserGuide.set(data.chordguide)
  64.  
  65.         else:
  66.             self.mode = "Scale Mode"
  67.             self.WhichUserGuide.set(data.scaleguide)
  68.  
  69.         self.ScaleChordVar.set(self.mode)
  70.  
  71.  
  72.     def OnPressEnter(self,event):
  73.         scale_or_chord = self.entryVariable.get()
  74.         mode = self.mode
  75.         ## if Quit or q or Q then exit program.
  76.         if scale_or_chord in ["quit", "q", "Q", "end", "End", "END", "exit", "Exit", "EXIT"]:
  77.  
  78.             self.quit()
  79.         ## if NOT Quit then call the main Python routine and get scale or chord notes
  80.         totalanswer = helper.main(scale_or_chord, mode)  # returns a string
  81.  
  82.         self.labelVariable.set(totalanswer)
  83.         self.entry.focus_set()
  84.         self.entry.selection_range(0, Tkinter.END)
  85.  
  86.  
  87. if __name__ == "__main__":
  88.     app = userinterface_tk(None)
  89.     app.title('Scale or Chord Notes ( design, concept and coding by Diliup Gabadamudalige 2015. diliupg@gmail.com )')
  90.  
  91.     app.iconbitmap(default = getinim.main("dg.ico"))
  92.  
  93.     app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement