Advertisement
here2share

# Tk_widgets_to_zoom.py

Jan 28th, 2021
1,332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. # Tk_widgets_to_zoom.py
  2.  
  3. import Tkinter as tk
  4.  
  5. root = tk.Tk()
  6. root.state('zoomed')
  7. widgets_to_zoom_list = []
  8. DEFAULT_SIZE = 50*5+5
  9.  
  10.  
  11. def zoom(widget):
  12.     for every_widget in widgets_to_zoom_list:
  13.         every_widget.config(width=widget.get()*5+5, height=widget.get()*5+5)
  14.  
  15. def main():
  16.     canvas = tk.Canvas(root)
  17.     frame = tk.Frame(canvas)
  18.     zoom_scale = tk.Scale(root, orient='vertical', from_=1, to=100)
  19.     zoom_scale.config(command=lambda args: zoom(zoom_scale))
  20.  
  21.     zoom_scale.set(50)
  22.  
  23.     pixel = tk.PhotoImage(width=1, height=1)
  24.     for i in range(60):
  25.         btn = tk.Button(frame, text=str(i + 1), bg='Blue', image=pixel, width=DEFAULT_SIZE, height=DEFAULT_SIZE, compound="c")
  26.         btn.grid(row=0, column=i)
  27.         widgets_to_zoom_list.append(btn)
  28.  
  29.     canvas.create_window(0, 0, anchor='nw', window=frame)
  30.     # make sure everything is displayed before configuring the scroll region
  31.     canvas.update_idletasks()
  32.  
  33.     canvas.configure(scrollregion=canvas.bbox('all'))
  34.     canvas.pack(fill='both', side='left', expand=True)
  35.     zoom_scale.pack(fill='y', side='right')
  36.     root.mainloop()
  37.  
  38.  
  39. if __name__ == '__main__':
  40.     main()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement