0

I am trying to read data from database and display it in the GUI. i have created a new frame in (Class : Signals) in the main menu. Under this i read data from DB and created a new Canvas widget and frame for that.In that new frame i am trying to create table from entry and show it to the user. Code build successflly and no error . Scroall bar also created but it is not movable. code is attached below. Any suggestions ?

def LoadMenu(self,controller):
    self.ActiveMenu = 'New'
    ##self.WidgHeaderDict = controller.Destroywidgets(self,self.WidgHeaderDict)
    ##self.WidgDataDict = controller.Destroywidgets(self,self.WidgDataDict)
    cwd = os.getcwd()
    in_path = askopenfilename(initialdir=cwd,
                       filetypes =(("Excel File", "*.xls"),("All Files","*.*")),
                       title = "Choose a file.")
    print('Currently in ',self.ActiveMenu,'Menu')
    df = pd.read_excel(in_path,'Msg_Overview')
    controller.CreatTablePrimaryKey('SignalMenu',self.Widglist,self.WidgType,'SlNo')
    for idx in range(len(df)):      
        row = df.iloc[idx,0:3]
        dict1 = row.to_dict()
        dict1['SlNo'] = idx + 1            
        controller.CreateEntryToTable('SignalMenu',dict1)
def ViewMenu(self,controller):
    self.ActiveMenu = 'View'
    self.WidgHeaderDict = controller.Destroywidgets(self,self.WidgHeaderDict)
    self.WidgDataDict = controller.Destroywidgets(self,self.WidgDataDict)
    record = controller.GetAlltabledata('SignalMenu')
    for idx,field in enumerate(self.Widglist):
        ent = Label(self,text=field,anchor = SW,justify=LEFT)
        ent.pack()
        ent.place(height=20,width=150,x=((idx*150)),y=60)
        self.WidgHeaderDict[field].append(ent)
    Ypos = 80
    self.canvas = tk.Canvas(controller, background="blue", borderwidth=0)
    self.frame = tk.Frame(self.canvas, background="green")
    self.scrolly = tk.Scrollbar(controller, orient="vertical", command=self.canvas.yview)
    self.scrollx = tk.Scrollbar(controller, orient="horizontal", command=self.canvas.xview)
    self.canvas.configure(yscrollcommand=self.scrolly.set, xscrollcommand=self.scrollx.set)
    self.canvas.create_window((4,4), window=self.frame, anchor="nw", tags="self.frame")
    self.scrolly.pack(side="right", fill="y")
    self.canvas.pack(side="top", fill="both", expand=True)
    self.scrollx.pack(side="bottom", fill="x")
    self.frame.bind("<Configure>", self.onFrameConfigure)
    print('Call before widget entry')
    print('self frame name is',self.frame)
    print('self name is',self)
    print('controller is',controller)
    for row in record:
        xpos = 0
        for idx,data in enumerate(row):
            xpos = (((idx)*150))
            ent = tk.Entry(self.canvas,textvariable=StringVar(self,value = data),state=DISABLED)
            ent.pack()
            ent.place(height=20,width=150,x=xpos,y=Ypos)
            field = self.Widglist[idx]
            self.WidgDataDict[field].append(ent)
        Ypos  = Ypos + 20

    print('Created widget entry')            
def onFrameConfigure(self, event):
    self.canvas.configure(scrollregion=self.canvas.bbox("all"))
    print('Screen Adjusted in ',self.ActiveMenu,'Menu')
  • 1
    Possible duplicate of [Calling an external command in Python](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – Prany Jul 05 '18 at 17:46
  • 1
    Possible duplicate of, related to, or helpful: [Tkinter Scrollbar not working](https://stackoverflow.com/questions/38780724/tkinter-scrollbar-not-working?rq=1) – davedwards Jul 05 '18 at 17:51
  • 1
    You are putting all of the entries in the canvas rather than in the frame in the canvas. – Bryan Oakley Jul 05 '18 at 18:59

0 Answers0