-2

I am using tkinter and Python 2.7 to make a COCOMO 2 Simulator. I have to get value of many cost and scale factors from user. For this, i am using radio buttons. Since there are many factors, my frame is not able to display all content.

For this, i tried adding scrollbar to the frame with the hep of this answer. I have to managed to get a scroll bar on the screen but nothing moves.

import Tkinter as tk
import ttk

LARGE_FONT = ("Verdana", 40)
BUTTON_FONT = ("Verdana", 20)
RADIO_FONT = ('Verdana', 15)


class GUI(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)

        container.pack(side="top", fill="both", expand = True)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)


        frame = Effort_Page(container, self)
        frame.grid(row=0, column=0, sticky="nsew")
        frame.tkraise()


class Effort_Page(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        vscrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
        vscrollbar.pack(fill=tk.Y, side=tk.RIGHT, expand=tk.FALSE)
        canvas = tk.Canvas(self, bd=0, highlightthickness=0,
                        yscrollcommand=vscrollbar.set)
        canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.TRUE)
        vscrollbar.config(command=canvas.yview)
        canvas.xview_moveto(0)
        canvas.yview_moveto(0)
        self.interior = interior = tk.Frame(canvas)
        interior_id = canvas.create_window(0, 0, window=interior,
                                           anchor="nw")
        self.set_costDrivers()
        labelH = tk.Label(self, text="Effort Calculator", font=LARGE_FONT)
        labelH.place(x=650, y=30)
        scale_driver_heading = tk.Label(self, text="Scale Drivers", font=BUTTON_FONT)
        scale_driver_heading.place(x=70, y=230)

        rc_vl = []
        v1 = [0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
        h = 0

        for i in range(5):

            rc_vl.append(tk.Radiobutton(self, 
                          text="VL", 
                          variable=v1[i], 
                          value=self.costDrivers["VL"][i] ))

            rc_vl[i].place(x=650, y=700+h)
            rc_vl[i].config(font=RADIO_FONT)
            h = h + 100

        def _configure_interior(event):
            # update the scrollbars to match the size of the inner frame
            size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
            canvas.config(scrollregion="0 0 %s %s" % size)
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the canvas's width to fit the inner frame
                canvas.config(width=interior.winfo_reqwidth())
        interior.bind('<Configure>', _configure_interior)

        def _configure_canvas(event):
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the inner frame's width to fill the canvas
                canvas.itemconfigure(interior_id, width=canvas.winfo_width())
        canvas.bind('<Configure>', _configure_canvas)

    def onFrameConfigure(self, event):
        '''Reset the scroll region to encompass the inner frame'''
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))

    def set_costDrivers(self):

        self.costDrivers = dict()
        self.costDrivers["VL"] = [0.75, 0, 0.75, 0, 0.89, 0, 0, 0, 1.50, 1.37, 1.24, 1.22,
                                1.25, 1.22, 1.24, 1.25, 1.29]

        self.costDrivers["L"] = [0.88, 0.93, 0.88, 0.91, 0.95, 0, 0, 0.87, 1.22, 1.16, 1.10,
                                1.10, 1.12, 1.10, 1.12, 1.10, 1.10]

        self.costDrivers["N"] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

        self.costDrivers["H"] = [1.15, 1.09, 1.15, 1.14, 1.06, 1.11, 1.06, 1.15, 0.83, 0.87,
                                0.92, 0.89, 0.88, 0.91, 0.86, 0.92, 1]

        self.costDrivers["VH"] = [1.39, 1.19, 1.30, 1.29, 1.13, 1.31, 1.21, 1.30, 0.67,
                                0.74, 0.84, 0.81, 0.81, 0.84, 0.72, 0.84, 1] 

        self.costDrivers["EH"] = [0, 0, 1.66, 1.49, 0, 1.67, 1.57, 0, 0, 0, 0, 0, 0, 0, 0,
                                0.78, 0]        


app = GUI()
app.geometry("2000x1600")
app.mainloop()
FrackeR011
  • 61
  • 10

1 Answers1

0

The code you posted won't run for several different reasons, so it's impossible to duplicate your problem.

However, it's clear that you aren't putting the radiobuttons inside the frame that is inside the canvas, so that is why they won't scroll. You need to put them inside the interior frame.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Sorry again. This time the code will run. I tried adding radio buttons to interior but then no button is displayed on screen – FrackeR011 Apr 28 '19 at 17:22