furas

Python - example [reddit/learnpython]

Oct 13th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. #
  2. # https://www.reddit.com/r/learnpython/comments/57dc9u/recreate_tkinter_frame/
  3. #
  4.  
  5. from PIL import Image
  6. from PIL import ImageTk
  7. from Tkinter import Tk, Frame
  8. from Tkinter import Button, LEFT, TOP, X, FLAT, RAISED, StringVar, Label
  9. import tkFileDialog
  10.  
  11. class UI():
  12.  
  13.     def __init__(self, parent):
  14.  
  15.         self.parent = parent
  16.  
  17.         self.showFrame = [0] * 14
  18.         self.showTempFrame = []
  19.  
  20.         for i in range(14):
  21.             var = StringVar()
  22.             self.showTempFrame.append(var)
  23.             self.showTempFrame[i].set("not set")
  24.  
  25.         self.currentShow = StringVar()
  26.         self.currentShow.set("date.log")
  27.         self.menuUI()
  28.         self.timelineUI()
  29.  
  30.     def menuUI(self):
  31.  
  32.         toolbar = Frame(self.parent, bd=1, relief=RAISED)
  33.  
  34.         # Open Button
  35.         self.openImg = Image.open("img/open.png")
  36.         openImgMenu = ImageTk.PhotoImage(self.openImg)
  37.  
  38.         openButton = Button(toolbar, image=openImgMenu, relief=FLAT,
  39.                            command=self.openShow)
  40.         openButton.image = openImgMenu
  41.         openButton.pack(side=LEFT, padx=2, pady=2)
  42.  
  43.     def timelineUI(self):
  44.  
  45.         self.timeline = Frame(self.parent)
  46.  
  47.         with open(self.currentShow.get()) as timelineShowFile:
  48.             timelineShowData = timelineShowFile.readlines()
  49.  
  50.         timelineCurrentFrame = 0
  51.  
  52.         for timelineFrame in timelineShowData:
  53.             for timelineFrameChannel in range(0, 13):
  54.                 if timelineFrame[timelineFrameChannel] == "0":
  55.                     timelineChannelStateLabel = Label(self.timeline, text="")
  56.                     timelineChannelStateLabel.grid(row=timelineFrameChannel, column=timelineCurrentFrame)
  57.  
  58.                 elif timelineFrame[timelineFrameChannel] == "1":
  59.                     timelineChannelStateLabel = Label(self.timeline, text="#")
  60.                     timelineChannelStateLabel.grid(row=timelineFrameChannel, column=timelineCurrentFrame)
  61.  
  62.             timelineCurrentFrame = timelineCurrentFrame + 1
  63.  
  64.         self.timeline.pack(side=TOP, fill=X)
  65.  
  66.     def openShow(self):
  67.         openFile = tkFileDialog.askopenfilename()
  68.         self.currentShow.set(openFile)
  69.         self.timeline.destroy()
  70.         self.timelineUI()
  71.  
  72.  
  73. def main():
  74.     root = Tk()
  75.     root.geometry("250x150+300+300")
  76.     root.minsize(400, 300)
  77.     app = UI(root)
  78.     root.mainloop()
  79.  
  80.  
  81. if __name__ == '__main__':
  82.     main()
Add Comment
Please, Sign In to add comment