0

I am Creating Multiple tab window using Notebook and in one of tab "Check Box" will created dynamically depending on the values in the Excel . (I am able to read values from Excel and Create the Check Box) . The Number of Check box will be equal to number values in the excel .

In my Excel I have values from 1 to 30 . But i am seeing values till 1 to 11 and other values are down in the UI , But scroll Bar is not active .

Please help me with this .

import tkinter as tk

from dicttoxml import dicttoxml
import xlrd


import GetValueFromExcel
from GetValueFromExcel import ExcelValue
from array import array
from tkinter import *
from tkinter import ttk, Button
from tkinter import *

root = Tk()
CheckBoxSelection=[]
NameOfVariable=[]
KeyName=[]
SelectedCheckbox=[]
dict={}
frame_main = tk.Frame(root)
frame_main.grid(sticky='news')
canvas=tk.Canvas()

class UICreation():

    def __init__(self):
        print ("I m in __init__")
        self.nb=ttk.Notebook(frame_main)
        self.page1=ttk.Frame(self.nb)
        self.page2=ttk.Frame(self.nb)


    def tabcreation(self):
        print ("I M in Tab Creation")
        self.nb.add(self.page1,text="Select")
        canvas = tk.Canvas(self.page1)
        canvas.grid(row=0, column=0, sticky="news")
        vsb = tk.Scrollbar(self.page1, orient="vertical", command=canvas.yview)
        vsb.grid(row=0, column=1, sticky='ns')
        canvas.configure(yscrollcommand=vsb.set)
        canvas.config(scrollregion=canvas.bbox("all"))
        f = tk.Frame(canvas)
        canvas.create_window((200, 0), window=f, anchor="n")
        self.nb.add(self.page2,text="Add")
        self.nb.grid(sticky=N)
        print ("I M in checkBox")
        ListNumber=len(List_key)
        print (ListNumber)
        for value in range(0,ListNumber, 1):
             NameOfVariable= "checkBox" + str(value)
             CheckBoxSelection.append("var"+str(value))
             CheckBoxSelection[value]=IntVar()
             NameOfVariable = Checkbutton(f, text=str(List_key[value]),variable=CheckBoxSelection[value])
             Checkbutton()
             NameOfVariable.grid(sticky=NW)
             NameOfVariable.cget("text")
             KeyName.append(NameOfVariable.cget("text"))

    def button(self):
         button = Button(frame_main, text="Submit", command=self.OnButtonClick)
         button.grid(sticky=NW)

    def OnButtonClick(self):
        index = 0
        SelectedCheckboxValue=[]
        for st in (CheckBoxSelection):
            if st.get():
                SelectedCheckboxKey=KeyName[index]
                SelectedCheckboxValue=GetValueFromExcel.row_data_dict[SelectedCheckboxKey]
                index+=1
                dict={
                "Properties": {"id": "ConnectJetSerialNumber"+SelectedCheckboxKey,"value":SelectedCheckboxValue[0],"PrinterName":SelectedCheckboxValue[1],"PrinterName2":SelectedCheckboxValue[2]}
                     }
                print(dict)
                xml = dicttoxml(dict, custom_root='test', attr_type=False)
                file=open(r"C:\SmallVille\SmallVilleAutoConfigGUI\Selected.xml","a")
                file.write(str(xml))
            else:
                index+=1


if __name__ == '__main__':
    ui = UICreation()
    ev = GetValueFromExcel.ExcelValue()
    t=ev.readExcelValue()
    print("I am before print t")
    print(t)
    print("I am before list")
    List_key= list(t.keys())
    print (List_key)
    ui.tabcreation()
    ui.button()
    root.mainloop()

UI Screen Shoot also attached My UI

  • 1
    You're configuring the `scrollregion` as the size of the canvas before anything is put in. At this point the size of the canvas is 1x1 so there is nothing to scroll. The best way to go is to use a bind on configuration of the frame as shown in [this answer](https://stackoverflow.com/a/3092341/3714930). – fhdrsdg May 29 '18 at 07:27
  • 1
    Another way would be to put `canvas.update()` and `canvas.config(scrollregion=canvas.bbox("all"))` *after* your loop that makes the Checkbuttons. – fhdrsdg May 29 '18 at 07:38
  • @fhdrsdgThanks .. This Worked –  May 29 '18 at 09:54

0 Answers0