Python Tkinter Custom Widget (Frame) with Mousewheel Scroll Event
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I try to write a GUI for practicing with one Window, containing two frames in a ttk.Notebook. Each of these Custom Widget Frames should have a scrollbar and the MouseWheel bound to a yscroll for the canvas which is placed in this frame.
My questions are:
- Is this a common/recommended way to do that?
- If I do it like this the MouseWheel works only on one of the Frames of my window. Why?
- I am a beginner, so if you see any other mistakes/uncommon things, please let me know!
Here is an extraction of my code:
from tkinter import *
import tkinter.ttk as ttk
class MyFirstGUI(object):
def __init__(self, master):
self.master = master
self.gui_control = ttk.Notebook(master)
self.main_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.systems_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.gui_control.add(self.main_gui, text='Main')
self.gui_control.add(self.systems_gui, text='Systems')
self.gui_control.grid(column=1,row=1, columnspan=9, rowspan=50,sticky=N+E+S+W)
self.test_1 = Main.MainFrame(self.main_gui)
self.test_1.grid(row=0, column=0, sticky="NESW")
self.test_2 = Systems.SystemFrame(self.systems_gui)
self.test_2.grid(row=0, column=0, sticky="NESW")
#[...]
master.mainloop()
MainGUI:
class MainFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.main_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.main_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.main_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.main_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.main_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
Systems GUI (basically the same):
class SystemFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.system_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.system_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.system_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.system_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.system_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
python beginner python-3.x gui tkinter
add a comment |Â
up vote
2
down vote
favorite
I try to write a GUI for practicing with one Window, containing two frames in a ttk.Notebook. Each of these Custom Widget Frames should have a scrollbar and the MouseWheel bound to a yscroll for the canvas which is placed in this frame.
My questions are:
- Is this a common/recommended way to do that?
- If I do it like this the MouseWheel works only on one of the Frames of my window. Why?
- I am a beginner, so if you see any other mistakes/uncommon things, please let me know!
Here is an extraction of my code:
from tkinter import *
import tkinter.ttk as ttk
class MyFirstGUI(object):
def __init__(self, master):
self.master = master
self.gui_control = ttk.Notebook(master)
self.main_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.systems_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.gui_control.add(self.main_gui, text='Main')
self.gui_control.add(self.systems_gui, text='Systems')
self.gui_control.grid(column=1,row=1, columnspan=9, rowspan=50,sticky=N+E+S+W)
self.test_1 = Main.MainFrame(self.main_gui)
self.test_1.grid(row=0, column=0, sticky="NESW")
self.test_2 = Systems.SystemFrame(self.systems_gui)
self.test_2.grid(row=0, column=0, sticky="NESW")
#[...]
master.mainloop()
MainGUI:
class MainFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.main_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.main_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.main_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.main_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.main_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
Systems GUI (basically the same):
class SystemFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.system_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.system_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.system_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.system_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.system_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
python beginner python-3.x gui tkinter
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I try to write a GUI for practicing with one Window, containing two frames in a ttk.Notebook. Each of these Custom Widget Frames should have a scrollbar and the MouseWheel bound to a yscroll for the canvas which is placed in this frame.
My questions are:
- Is this a common/recommended way to do that?
- If I do it like this the MouseWheel works only on one of the Frames of my window. Why?
- I am a beginner, so if you see any other mistakes/uncommon things, please let me know!
Here is an extraction of my code:
from tkinter import *
import tkinter.ttk as ttk
class MyFirstGUI(object):
def __init__(self, master):
self.master = master
self.gui_control = ttk.Notebook(master)
self.main_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.systems_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.gui_control.add(self.main_gui, text='Main')
self.gui_control.add(self.systems_gui, text='Systems')
self.gui_control.grid(column=1,row=1, columnspan=9, rowspan=50,sticky=N+E+S+W)
self.test_1 = Main.MainFrame(self.main_gui)
self.test_1.grid(row=0, column=0, sticky="NESW")
self.test_2 = Systems.SystemFrame(self.systems_gui)
self.test_2.grid(row=0, column=0, sticky="NESW")
#[...]
master.mainloop()
MainGUI:
class MainFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.main_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.main_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.main_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.main_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.main_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
Systems GUI (basically the same):
class SystemFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.system_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.system_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.system_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.system_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.system_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
python beginner python-3.x gui tkinter
I try to write a GUI for practicing with one Window, containing two frames in a ttk.Notebook. Each of these Custom Widget Frames should have a scrollbar and the MouseWheel bound to a yscroll for the canvas which is placed in this frame.
My questions are:
- Is this a common/recommended way to do that?
- If I do it like this the MouseWheel works only on one of the Frames of my window. Why?
- I am a beginner, so if you see any other mistakes/uncommon things, please let me know!
Here is an extraction of my code:
from tkinter import *
import tkinter.ttk as ttk
class MyFirstGUI(object):
def __init__(self, master):
self.master = master
self.gui_control = ttk.Notebook(master)
self.main_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.systems_gui = ttk.Frame(self.gui_control, borderwidth=0)
self.gui_control.add(self.main_gui, text='Main')
self.gui_control.add(self.systems_gui, text='Systems')
self.gui_control.grid(column=1,row=1, columnspan=9, rowspan=50,sticky=N+E+S+W)
self.test_1 = Main.MainFrame(self.main_gui)
self.test_1.grid(row=0, column=0, sticky="NESW")
self.test_2 = Systems.SystemFrame(self.systems_gui)
self.test_2.grid(row=0, column=0, sticky="NESW")
#[...]
master.mainloop()
MainGUI:
class MainFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.main_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.main_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.main_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.main_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.main_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
Systems GUI (basically the same):
class SystemFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.system_canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0)
self.system_canvas.grid(row=0,column=0, sticky="NESW")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.system_canvas.yview)
self.vsb.grid(row=0,column=1, sticky="NS")
self.system_canvas.bind_all("<MouseWheel>", self._on_mousewheel)
def _on_mousewheel(self, event):
self.system_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#[...]
python beginner python-3.x gui tkinter
edited May 25 at 9:18
Ludisposed
5,68621656
5,68621656
asked May 25 at 8:55
K-Doe
533
533
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f195146%2fpython-tkinter-custom-widget-frame-with-mousewheel-scroll-event%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password