Python Forum
Scoll widget help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scoll widget help
#1
I have peeked on the forum for an answer but I have not found what I am after.

Being new to python I am looking for a place that will offer good advise and mentoring to learn the correct syntax for this language. I have been doing some reading and there is a lot of useless information out there and some of it is a touch confusing because the code is not explained. I am not one to be fed code without explanation... I prefer to learn the code and the how's and why's it is done what it is doing in the syntax that is it in.

I am writing a small piece and I have created a window and in the window I have added LabelFrames. There are multiple labelframes added (15 and adding more). I have the window scaled to w=1420 h=920 so the labelframe widgets cannot all be seen within the window size. Can a scroll bar widget be added to the window to allow the labelframes to be scrolled down to view the others?
I have read where it has been said that I should be writing it as a canvas and then adding a scroll to that, can a window not contain a scroll to do what I am after?
"Often stumped... But never defeated."
Reply
#2
Quote: I have created a window
Need to know:
  • using which GUI package? You can add scrolls (vertical and/or horizontal) to most container widgets (frames, canvases, Treeview, Listview, etc) But the methods to do so are dependent on the graphics package being used, so need to know that.
  • Code you are working on, Read about BBCODE tags) so we can see what we are dealing with.
  • Python version you are using.
  • Operating system
Reply
#3
I am using Tkinter for the GUI and I am still quite new to programming python and using Tkinter.

I setup a window:
window1 = tkinter.Tk()
window1.title('Test window')
w = 1420
h = 940
ws = window1.winfo_screenwidth()
hs = window1.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
window1.geometry('%dx%d+%d+%d' % (w, h, x, y))
x = (window1.winfo_screenwidth() - window1.winfo_reqwidth()) / 2
y = (window1.winfo_screenheight() - window1.winfo_reqheight()) / 2
window1.configure(background='Alice blue')
header = Label(font=('arial',20, 'bold'), text = " Test program ", fg='Steel Blue',bd=3, bg='light steel blue', relief = RIDGE)
header.place(relx=0.5, rely=0.04, anchor=CENTER)
must_complete = Label(font=('arial',10, 'bold'), text = "All fields must be completed before submitting", fg='Steel Blue',bd=10, bg='alice blue').pack(side=BOTTOM)
I then added labelframes:
#================================== INTRO FRAME ==================================
adminlabel = LabelFrame(window1, text="Administration", width=1375, height=55, bd=3, fg='steel blue', bg='alice blue')
adminlabel.place(relx=0.5, rely=0.128, anchor=CENTER)
E1 = Label(adminlabel,font=('arial',10,'bold'), text='Agent: ', fg='steel blue', bg='alice blue')
E1.place(relx=0.023,rely=0.390, anchor=CENTER)
agent = Entry(adminlabel, font=('arial',10,'bold'), textvariable= agent, width=20, bg = 'alice blue', bd=2, fg='steel blue', insertwidth=2, justify=LEFT, relief=SUNKEN)
agent.place(relx=0.095,rely=0.390, anchor=CENTER)
SC1 = Label(adminlabel,font=('arial',10,'bold'), text='Scored by: ', fg='steel blue', bg='alice blue')
SC1.place(relx=0.243,rely=0.390, anchor=CENTER)
scored_by = Entry(adminlabel, font=('arial',10,'bold'), textvariable= scored, width=20, bg = 'alice blue', fg='steel blue', bd=2, insertwidth=2, justify=LEFT, relief=SUNKEN)
scored_by.place(relx=0.326,rely=0.390, anchor=CENTER)
D1 = Label(adminlabel,font=('arial',10,'bold'), text='Date: ', fg='steel blue', bg='alice blue')
D1.place(relx=0.475,rely=0.390, anchor=CENTER)
date = Entry(adminlabel, font=('arial',10, 'bold'), textvariable= date, width=20, bg = 'alice blue', bd=2, fg='steel blue', insertwidth=2, justify=LEFT, relief=SUNKEN)
date.place(relx=0.545,rely=0.390, anchor=CENTER)
agent.focus(
#================================== INTRO FRAME ==================================
intro = LabelFrame(window1, text="Introduction", width=1375, height=100, bd=3, fg='steel blue', bg='alice blue')
intro.place(relx=0.5, rely=0.22, anchor=CENTER)
Q1 = Label(intro,font=('arial',10,'bold'), text='Question 1 goes here', fg='steel blue', bg='alice blue')
Q1.place(relx=0.145,rely=0.15, anchor=CENTER)
Q2 = Label(intro,font=('arial',10,'bold'), text='Question 2 goes here', fg='steel blue', bg='alice blue')
Q2.place(relx=0.14,rely=0.45, anchor=CENTER)
Q3 = Label(intro,font=('arial',10,'bold'), text='Question 3 goes here', fg='steel blue', bg='alice blue')
Q3.place(relx=0.126,rely=0.75, anchor=CENTER)
Q1E = Entry(intro, font=('arial',10), textvariable= Q1E, width=5, bg = 'alice blue', bd=2, insertwidth=2, justify=CENTER, relief=SUNKEN)
Q2E = Entry(intro, font=('arial',10), textvariable= Q2E, width=5, bg = 'alice blue', bd=2, insertwidth=2, justify=CENTER, relief=SUNKEN)
Q3E = Entry(intro, font=('arial',10), textvariable= Q3E, width=5, bg = 'alice blue', bd=2, insertwidth=2, justify=CENTER, relief=SUNKEN)
Q1E.place(x=800,y=12, anchor=CENTER)
Q2E.place(x=800,y=36, anchor=CENTER)
Q3E.place(x=800,y=60, anchor=CENTER)
Q1CB = Button(intro, font=('arial',12,'bold'), text='Button 1', width=10, height=1, bg='aliceblue', fg='steel blue')#, command = comment)
Q1CB.place(x=875,y=20)
Q1RB = Button(intro, font=('arial',12,'bold'), text='Button 2', width=10, height=1, bg='aliceblue', fg='steel blue')#, command = comment)
Q1RB.place(x=1040,y=20)
Q1RPB = Button(intro, font=('arial',12,'bold'), text='Button 3', width=10, height=1, bg='aliceblue', fg='steel blue')#, command = comment)
Q1RPB.place(x=1205,y=20)
There are a number of additional labelframes such as the one above also added so a scroll would be needed to allow then to be seen when the program is run.
"Often stumped... But never defeated."
Reply
#4
you can find a good tutorial here: https://tkdocs.com/tutorial/index.html

Since you are new to python, you might want to consider another GUI package or at least keep it in the back of your mind for when you are ready to move up.
Tkinter in my opinion is not the best as a learning tool because:
  • It's limited in what it's capable of, the widget set is quite small
  • Geometry, for any windows more complicated than two or three frames is difficult at best when it comes to proper sizing, resizing, and even elementary layout.
  • There are some fantastic alternatives that have rich widget sets, are easy to learn and automatically control resizing, docking, and many other aspects of GUI layout.
  • The other GUI packages have the added bonus of web widget sets, including browsers.
So what's available? there are a bunch of GUI packages available, but in my opinion the top two are:
wxpython which can be installed with:
pip install wxpython
and Qt5 which is making a major commitment to python, see: http://blog.qt.io/blog/2018/04/13/qt-for...-near-you/

My personal choice is wxpython, but only the python 3 version (known as phoenix)
Reply
#5
My apologies for such a delay, I was out of country for a while due to work.

I am currently looking into the two alternatives you have mentioned for GUI but I have read that tk scroll widget is functional with "Lists" and "Canvas" widgets in tkinter. I had also read that using a canvas and then adding frame widget can be done successfully with a scroll.

I am quite new to this programming language and I have a strong desire to become proficient with python but getting good information that is easily understood without a lot of subtext which is not relevant to specifics in a question is hard to find when looking up information online at times... some places are worse than others.

In essence this is what I am doing. I have created a main window (named root), and added multiple labelFrame widgets, one labelFrame widget for each subject matter. As an example each labelFrame is for an educational course... math, english, science, geography, biology, history and so on. Each labelFrame widget is assigned to the main window.

There are many labelFrame widgets which exceed he size of the window and I am trying to get it to allow the user to scroll further to access he other labelFrame widgets.

Currently there are 14 labelFrame widgets and only 7 1/2 labelFrames that can be viewed in the window because it cannot be scrolled yet.
The window size is:
w = 1420
h = 940

Thoughts?
"Often stumped... But never defeated."
Reply
#6
Quote:I am quite new to this programming language and I have a strong desire to become proficient with python but getting good information that is easily understood without a lot of subtext which is not relevant to specifics in a question is hard to find when looking up information online at times... some places are worse than others.

I know the frustration you feel about getting a lot of subtext. Sometimes finding how to use the most elementary commands can bring a dissertation on the subject when looking for just the facts. However it can also be just as frustrating to get an explanation that's missing the details.

So for tkinter, here's a (the best, even though not recent) reference that is outstanding. All the facts needed, without the fluff:
http://infohost.nmt.edu/tcc/help/pubs/tk...index.html
and pdf version here: http://www.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf

You will find what you need with all the important (and necessary in programming) details for writing a tkinter application.

I also point you to an application which I wrote that uses scrollbars: https://github.com/Larz60p/CaliforniaPublicSalaries
It's only two modules, and you can see how the scrollbars are used. Module: CaCompGui.py, see method: create_frame3, widgets tree_down_scrolly and tree_down_scrollx

I think you probably want to use tk.Frame, and not LabelFrame
Reply


Forum Jump:

User Panel Messages

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