Hi, can someone please help me. I am new to Python and I am having problems with scrollbars not scrolling my buttons in window1, only the background numbers-text is scrolling with scrollbars, which I dont need. How can I make my buttons with icons scroll up\down, and sideways with scrollbars in window1?
Regards
Kraco
My code is:
Regards
Kraco
My code is:
import tkinter as tk # for label frame named in this software tk from tkinter import ttk # for Canvas scrollbar for buttons with images from winsound import * # for sound from tkinter import * # for photo images # Sound Files play1 = lambda: PlaySound('c:\images\siren.wav', SND_FILENAME) play2 = lambda: PlaySound('c:\images\pling.wav', SND_FILENAME) # Windows definitions def new_window1(): # Window1 definitions # Image files to be uploaded in window1 photo1 = PhotoImage(file="C:\images\plane.png") photo2 = PhotoImage(file="C:\images\car.png") photo3 = PhotoImage(file="c:\images\_apple.png") " new window" try: if win1.state() == "normal": win1.focus() except NameError as e: print(e) win1 = tk.Toplevel() win1.geometry("400x400+500+200") # Window1 frame opening size win1["bg"] = "green" # Window1 background colour # Canvas scrollbar for buttons with images c = Canvas(win1) hsb = Scrollbar(win1, orient="h", command=c.xview) vsb = Scrollbar(win1, orient="v", command=c.yview) c.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) c.grid(row=0, column=0, sticky="nsew") hsb.grid(row=1, column=0, stick="ew") vsb.grid(row=0, column=1, sticky="ns") win1.grid_rowconfigure(0, weight=1) win1.grid_columnconfigure(0, weight=1) c.configure(scrollregion=(0, 0, 5000, 5000)) for x in range(100, 5000, 100): for y in range(100, 5000, 100): c.create_text((x, y), anchor=CENTER, text="%d,%d" % (x, y)) # Buttons lb = tk.Label(c, text="Window1") # Create label-frame window1,position for text in label-frame window1 lb.grid(row=0, column=2) # text location in window1 in framw window1 Button1 = tk.Button(c, text="plane", command=play1, image=photo1) Button1.grid(row=1, column=1) Button2 = tk.Button(c, text="car", command=play2, image=photo2) Button2.grid(row=2, column=1) Button3 = tk.Button(c, text="apple", command=play2, image=photo3) Button3.grid(row=3, column=2) Button4 = tk.Button(c, text="apple", command=play2, image=photo3) Button4.grid(row=4, column=2) Button5 = tk.Button(c, text="apple", command=play2, image=photo3) Button5.grid(row=5, column=2) Button6 = tk.Button(c, text="apple", command=play2, image=photo3) Button6.grid(row=6, column=2) Button7 = tk.Button(c, text="apple", command=play2, image=photo3) Button7.grid(row=7, column=2) Button8 = tk.Button(c, text="apple", command=play2, image=photo3) Button8.grid(row=8, column=2) Button9 = tk.Button(c, text="apple", command=play2, image=photo3) Button9.grid(row=9, column=2) Button10 = tk.Button(c, text="apple", command=play2, image=photo3) Button10.grid(row=10, column=2) Button11 = tk.Button(c, text="apple", command=play2, image=photo3) Button11.grid(row=11, column=2) Button12 = tk.Button(c, text="apple", command=play2, image=photo3) Button12.grid(row=12, column=2) Button13 = tk.Button(c, text="apple", command=play2, image=photo3) Button13.grid(row=13, column=2) Button14 = tk.Button(c, text="apple", command=play2, image=photo3) Button14.grid(row=14, column=2) Button15 = tk.Button(c, text="apple", command=play2, image=photo3) Button15.grid(row=15, column=2) Button16 = tk.Button(c, text="apple", command=play2, image=photo3) Button16.grid(row=16, column=2) Button7 = tk.Button(c, text="apple", command=play2, image=photo3) Button7.grid(row=1, column=3) lb.pack() # Close window1 frame with buttons def new_window2(): # Image files to be uploaded in window1 photo1 = PhotoImage(file="C:\images\plane.png") photo2 = PhotoImage(file="C:\images\car.png") photo3 = PhotoImage(file="c:\images\_apple.png") " new window" try: if win2.state() == "normal": win2.focus() except NameError as e: print(e) win2 = tk.Toplevel() win2.geometry("300x300+500+200") # Window2 frame opening size win2["bg"] = "navy" # Window2 background colour lb2 = tk.Label(win2, text="Window2") # Create label-frame window2,position for text in label-frame window2 lb2.grid(row=0, column=1) # Position for text in label-frame window2 Button1 = tk.Button(win2, text="plane", command=play1, image=photo1) Button1.grid(row=1, column=1) Button2 = tk.Button(win2, text="car", command=play2, image=photo2) Button2.grid(row=2, column=1) Button2 = tk.Button(win2, text="apple", command=play2, image=photo3) Button2.grid(row=1, column=2) lb2.pack() # Close window2 frame with buttons def new_window3(): " new window" try: if win2.state() == "normal": win3.focus() except NameError as e: print(e) win1 = tk.Toplevel() win1.geometry("300x300+500+200") win1["bg"] = "yellow" lb = tk.Label(win1, text="Window3") lb.pack() # Buttons on menu frame win = tk.Tk() win.geometry("200x200+200+100") button = tk.Button(win, text="Open new Window1") button['command'] = new_window1 button.pack() button = tk.Button(win, text="Open new Window2") button['command'] = new_window2 button.pack() button = tk.Button(win, text="Open new Window3") button['command'] = new_window3 button.pack() win.mainloop()