Advertisement
Uno-Dan

Untitled

Nov 11th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. from tkinter import messagebox
  2.  
  3. from tkapp.base import App
  4. from tkapp.constants import LAST_ROW, LAST_COLUMN
  5.  
  6.  
  7. def main():
  8.  
  9.     app = App(
  10.         title='Demo Application',
  11.         admin_open=True,
  12.         admin_close=False,
  13.         defaults=defaults
  14.     )
  15.  
  16.     def progress_bar1(window):
  17.         win = app.get_window(window.id)
  18.         pb = win.get('content/middle_pane/progress/bar').progressbar
  19.  
  20.         def animate():
  21.             pb.count += 500
  22.             pb['value'] = pb.count
  23.             if pb.count < pb['maximum']:
  24.                 pb.after(pb.refresh_rate, animate)
  25.             else:
  26.                 messagebox.showinfo('Info', 'Process Completed Successfully')
  27.  
  28.         win.get('content/middle_pane/progress/start').button.config(command=animate)
  29.  
  30.     def progress_bar2(window):
  31.         win = app.get_window(window.id)
  32.         pb = win.get('content/middle_pane/notebook').tab('one').get('progress/bar').progressbar
  33.         scale = win.get('content/middle_pane/notebook').tab('one').get('scale').scale
  34.  
  35.         def animate(count=None):
  36.             if count:
  37.                 pb.count = 0
  38.  
  39.             pb.count += 500
  40.             pb['value'] = pb.count
  41.             if pb.count < pb['maximum']:
  42.                 pb.after(int(scale.get()), animate)
  43.             else:
  44.                 messagebox.showinfo('Info', 'Process Completed Successfully')
  45.  
  46.         win.get('content/middle_pane/notebook').tab('one').get('progress/start').button.config(command=lambda: animate(1))
  47.  
  48.     def create_process1(window):
  49.         win = app.get_window(window.id)
  50.  
  51.         def message():
  52.             messagebox.showinfo('Info', 'This is process 1 ' + window.id)
  53.  
  54.         win.get('content/right_pane/create_process1').button.config(command=message)
  55.  
  56.     def create_process2(window):
  57.         win = app.get_window(window.id)
  58.  
  59.         def message():
  60.             messagebox.showinfo('Info', 'This is process 2 ' + window.id)
  61.  
  62.         win.get('content/right_pane/create_process2').button.config(command=message)
  63.  
  64.     def setup_process1(window):
  65.         messagebox.showinfo('Info', 'after_open hook.')
  66.  
  67.     def setup_process2(window):
  68.         messagebox.showinfo('Info', 'before_open hook.')
  69.  
  70.     def destroy_process1():
  71.         messagebox.showinfo('Info', 'before_close hook.')
  72.  
  73.     def destroy_process2():
  74.         messagebox.showinfo('Info', 'after_close hook.')
  75.  
  76.     def update_scale(window, val=None):
  77.         tab = window.get('content/middle_pane/notebook').tab('one')
  78.         label = tab.get('lscale')
  79.         scale = tab.get('scale').scale
  80.  
  81.         if val is not None:
  82.             label.var.set(int(float(val)))
  83.         else:
  84.             label.var.set(int(scale.get()))
  85.  
  86.     def refresh_scale(window):
  87.         def scale(value):
  88.             update_scale(window, value)
  89.  
  90.         window.get('content/middle_pane/notebook').tab('one').get('scale').scale.config(command=scale)
  91.  
  92.     app.add_callback('window1', 'after_open', progress_bar1)
  93.     app.add_callback('window1', 'after_open', progress_bar2)
  94.     app.add_callback('window1', 'after_open', update_scale)
  95.     app.add_callback('window1', 'after_open', refresh_scale)
  96.  
  97.     app.add_callback('window2', 'after_open', create_process1)
  98.     app.add_callback('window2', 'after_open', create_process2)
  99.  
  100.     app.remove_callback('window2', 'after_open', create_process1)
  101.  
  102.     app.add_callback('window2', 'after_open', setup_process1)
  103.     app.add_callback('window2', 'before_open', setup_process2)
  104.     app.add_callback('window2', 'before_close', destroy_process1)
  105.     app.add_callback('window2', 'after_close', destroy_process2)
  106.  
  107.     app.init_windows().mainloop()
  108.  
  109.  
  110. if __name__ == '__main__':
  111.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement