Python Forum
[Tkinter] Scroll Bars going backwards
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scroll Bars going backwards
#1
I am having difficulty with my scroll bars sliding backward. Code below.

user_dict = {"J Schmo":["SSM", "CPP"], "B Kezzi":["SM", "OBSIC"], "J juk":["SSM", "CPP"]}
system_type = {"Controller":["SSM", "CPP", "SM"], "CTD":["SSM", "SM"], "MMP":["SSM", "CPP"], "Acomm":["SSM"], "D2": ["OBSIC"]}
user_variables = {"000System SN": ["CTD", "SSM", "SM", "OBSIC"], "001System IP": ["CTD", "MMP", "SSM", "SM", "OBSIC"], "002System Name":
 ["MMP", "SSM", "SM", "OBSIC"]}
system_variables = {"000Initial Main V": ["CTD", "SSM", "SM", "OBSIC"],"001Initial Main I": ["CTD", "SSM", "SM", "OBSIC", "D2"]}
user_buttons = {"LOGIN": ["SSM", "CPP", "SM"], "Get Address": ["SSM", "CPP"], "Connect": ["OBSIC"], "Begin Test": ["OBSIC"], "Get initial Q330 V&I": ["OBSIC", "D2"]}

users = list(user_dict.keys())  # Grabs all users from user_dict and put them in a list called users
User_Variable_Entry = {}
User_Variable_Label = {}
System_Variable_Entry = {}
System_Variable_Label = {}

def in_group(dictionary, group):
    temp = []
    for key, groups in dictionary.items():
        if group in groups:
            temp.append(key)
    return temp

def system_type_menu(selection):
     global system
     system = selection
     systems = in_group(system_type, selection)
     Userlist = OptionMenu (frm, system_type_var, *systems, command = test_data) # Step Three
     Userlist.grid(row=2, column=0,pady=10)

def group_menu(selection):
    groups = user_dict[selection]
    Userlist = OptionMenu (frm, group_var, *groups, command = system_type_menu) # Step Two
    Userlist.grid(row=1, column=0,padx=5)

def test_data(selection): # Step Four
   UVP = 20 ##User Variable Position
   lb = list()
   for k, v in sorted(user_variables.items()):
      if system in v:
         name = (k)
         e = Entry(frm, width=25)
         e.grid(sticky=W,row=UVP, column=3)
         User_Variable_Entry[name] = e
         lb = Label(frm, width=25, text=name[3:])
         lb.grid(row=UVP, column=15)
         User_Variable_Label[name] = lb
         UVP += 30

   BPH = 420
   BPV = 525
   x=0
   for k, v in sorted(user_buttons.items()):
      if system in v:
         BV = k
         if (x == 3):
            x=0
            BPV += 30
            BPH = 420
         BV = Button(frm, width=20, bg = "green", fg = "white", text=BV)
         BV.grid(row=BPH, column=BPV)
         BPH += 200
         x += 1

   SVP = 50 ##System Variable Position
   lb = list()
   for k, v in sorted(system_variables.items()):
      if system in v:
         name = (k)
         e1 = Entry(frm, width=25)
         e1.grid(row=1275, column=SVP)
         System_Variable_Entry[name] = e1
         lb1 = Label(frm, width=25, text=name[3:])
         lb1.grid(row=1050, column=SVP)
         System_Variable_Label[name] = lb1
         SVP += 30

def get_data():
    for k in sorted(user_variables.keys()):
      print(k.get())

def print_user_variables():
    for name in sorted(User_Variable_Entry):
        print ((name[3:]),User_Variable_Entry[name].get())


from tkinter import *
## Main window
root = Tk()
## Grid sizing behavior in window
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
## Canvas
cnv = Canvas(root)
cnv.grid(row=0, column=0, sticky='nswe')
## Scrollbars for canvas
hScroll = Scrollbar(root, orient=HORIZONTAL, command=cnv.xview)
hScroll.grid(row=1, column=0, sticky='we')
vScroll = Scrollbar(root, orient=VERTICAL, command=cnv.yview)
vScroll.grid(row=0, column=1, sticky='ns')
cnv.configure(xscrollcommand=hScroll.set, yscrollcommand=vScroll.set)

## Frame in canvas
frm = Frame(cnv, bg='cyan')
## This puts the frame in the canvas's scrollable zone
cnv.create_window(0, 0, window=frm, anchor='nw')
## Frame contents

a = StringVar()

title_label = Label(frm, text="My Software}",font=(None, 36),bg='cyan',fg = "blue")
title_label.place(x=20, y=0)

Run_now = Button(frm, text="Run", fg="blue", command=print_user_variables)
Run_now.place(x=500, y=20)

Exit_now = Button(frm, text="Quit", fg="blue", command=root.destroy)
Exit_now.place(x=500, y=40)

UV_Label = Label(frm, bg="cyan", fg="blue", text="USER VARIABLES",font=(None, 18))
UV_Label.place(x=10, y=60)

SV_Label = Label(frm, width=25,bg='cyan',fg = "blue", text="SYSTEM VARIABLES",font=(None, 18))
SV_Label.place(x=10, y=80)

user_var = StringVar()
user_var.set ('Enter details')

system_type_var = StringVar()
system_type_var.set ('Select System Type')

group_var = StringVar()
group_var.set ('Select Group')

var=StringVar()
var.set ('Select User')
Userlist = OptionMenu (frm, var, *users, command = group_menu) # Step One Changed *list to *users, added command = group_menu
Userlist.grid(row=0, column=0)


## Update display to get correct dimensions
frm.update_idletasks()
## Configure size of canvas's scrollable zone
cnv.configure(scrollregion=(0, 0, frm.winfo_width(), frm.winfo_height()))

root.mainloop()
Reply
#2
You are trying to scroll the root window, which can't be scrolled.
Also, the hierarchy of your windows isn't right
should be:
frame in root (you have this right)
canvas in frame (you have it attached to root)
scrollbars attached to canvas, but linked to frame. It's hard to explain what i mean here.
you can find an example that you can follow in the following code: https://github.com/Larz60p/CaliforniaPub...CompGui.py
Reply
#3
Thank you for the response, I don't see where I have the frame attached to root
canvas in frame (you have it attached to root)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] QTableView: scroll to top cell of the screen random_nick 2 2,765 Oct-08-2022, 12:29 AM
Last Post: random_nick
Photo [PyQt] Connecting progress bars to sensors anastejzja 1 1,122 May-28-2022, 09:09 AM
Last Post: Axel_Erfurt
  [PyQt] How do I get a QScrollArea to scroll? LavaCreeperKing 9 7,599 Oct-29-2021, 08:33 AM
Last Post: Axel_Erfurt
  Treeview scroll selected node to top rfresh737 1 2,668 Apr-14-2021, 03:27 AM
Last Post: deanhystad
  [Tkinter] canvas widget scroll issue chrisdb 2 3,777 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  [Tkinter] Help with scroll bars kraco 1 2,205 Sep-27-2020, 11:20 PM
Last Post: Larz60+
  [Tkinter] How to place scroll bar correctly scratchmyhead 1 3,896 May-18-2020, 04:17 PM
Last Post: scratchmyhead
  Scroll frame with MouseWheel Nemesis 1 3,556 Mar-25-2020, 09:29 PM
Last Post: Nemesis
  [Kivy] Why I have to click twice to scroll? Hummingbird 0 2,326 Jan-06-2020, 09:08 PM
Last Post: Hummingbird
  Require scroll bars horizontal and vertical throughout the window tejgandhi 2 2,675 Jun-28-2019, 03:13 AM
Last Post: tejgandhi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020