0

I'm trying to add a scrollbar in the main window (janela), only to see line 33. Using the grid method, but this is seeming impossible to me. I have already understood that the canvas should be used, but I can not adapt the examples to my situation.

Any way?

from tkinter import *
import sqlite3
from tkinter.ttk import Combobox

janela = Tk()

yscrollbar = Scrollbar(janela, orient=VERTICAL)

yscrollbar.grid(row=2, rowspan=50, column=40, sticky=N + S)

canvas = Canvas(janela, bd=0, width=1, heigh=1)

canvas.grid(row=0, column=0, sticky=N + S + E + W)

yscrollbar.config(command=canvas.yview)

canvas.config(yscrollcommand=yscrollbar.set, scrollregion=(0, 0, 100, 100))

    class Frames(object):

        def __init__(self):
            pass    

        def main_frame(self, janela):
            janela.geometry("1200x600+100+100")
            cota1 = (Label(janela, text="1", width=7,font=("Calibri", "12"))).grid(row=4, column=6)
            cota2 = (Label(janela, text="2", width=7,font=("Calibri", "12"))).grid(row=5, column=6)
            cota3 = (Label(janela, text="3", width=7,font=("Calibri", "12"))).grid(row=6, column=6)
            cota4 = (Label(janela, text="4", width=7,font=("Calibri", "12"))).grid(row=7, column=6)
            cota5 = (Label(janela, text="5", width=7,font=("Calibri", "12"))).grid(row=8, column=6)
            cota6 = (Label(janela, text="6", width=7,font=("Calibri", "12"))).grid(row=9, column=6)
            cota7 = (Label(janela, text="7", width=7,font=("Calibri", "12"))).grid(row=10, column=6)
            cota8 = (Label(janela, text="8", width=7,font=("Calibri", "12"))).grid(row=11, column=6)
            cota9 = (Label(janela, text="9", width=7,font=("Calibri", "12"))).grid(row=12, column=6)
            cota10 = (Label(janela, text="10", width=7,font=("Calibri", "12"))).grid(row=13, column=6)
            cota11 = (Label(janela, text="11", width=7,font=("Calibri", "12"))).grid(row=14, column=6)
            cota12 = (Label(janela, text="12", width=7,font=("Calibri", "12"))).grid(row=15, column=6)
            cota13 = (Label(janela, text="13", width=7,font=("Calibri", "12"))).grid(row=16, column=6)
            cota14 = (Label(janela, text="14", width=7,font=("Calibri", "12"))).grid(row=17, column=6)
            cota15 = (Label(janela, text="15", width=7,font=("Calibri", "12"))).grid(row=18, column=6)
            cota16 = (Label(janela, text="16", width=7,font=("Calibri", "12"))).grid(row=19, column=6)
            cota17 = (Label(janela, text="17", width=7,font=("Calibri", "12"))).grid(row=20, column=6)
            cota18 = (Label(janela, text="18", width=7,font=("Calibri", "12"))).grid(row=21, column=6)
            cota19 = (Label(janela, text="19", width=7,font=("Calibri", "12"))).grid(row=22, column=6)
            cota20 = (Label(janela, text="20", width=7,font=("Calibri", "12"))).grid(row=23, column=6)
            cota21 = (Label(janela, text="21", width=7,font=("Calibri", "12"))).grid(row=24, column=6)
            cota22 = (Label(janela, text="22", width=7,font=("Calibri", "12"))).grid(row=25, column=6)
            cota23 = (Label(janela, text="23", width=7,font=("Calibri", "12"))).grid(row=26, column=6)
            cota24 = (Label(janela, text="24", width=7,font=("Calibri", "12"))).grid(row=27, column=6)
            cota25 = (Label(janela, text="25", width=7,font=("Calibri", "12"))).grid(row=28, column=6)
            cota26 = (Label(janela, text="26", width=7,font=("Calibri", "12"))).grid(row=29, column=6)
            cota27 = (Label(janela, text="27", width=7,font=("Calibri", "12"))).grid(row=30, column=6)
            cota28 = (Label(janela, text="28", width=7,font=("Calibri", "12"))).grid(row=31, column=6)
            cota29 = (Label(janela, text="29", width=7,font=("Calibri", "12"))).grid(row=32, column=6)
            cota30 = (Label(janela, text="30", width=7,font=("Calibri", "12"))).grid(row=33, column=6)

        def Antunes_frame(self):
            janelaAC_96 = Toplevel()
            janelaAC_96.geometry("1400x750+150+150")


app = Frames()
app.main_frame(janela)
janela.mainloop()
leandurus
  • 25
  • 5
  • 1
    Aside from your scrollbar question, you should check out this question about creating multiple widgets using a loop. https://stackoverflow.com/questions/27067094/how-can-i-create-multiple-tkinter-widgets-with-different-names-in-a-loop – Lafexlos Aug 22 '17 at 14:11
  • 1
    Why can't you adapt the other examples to your code? What's stopping you? – Bryan Oakley Aug 22 '17 at 14:14
  • 1
    FWIW, all of your variables (`cota1`, `cota2`, etc) will all be set to `None`. See https://stackoverflow.com/a/1101765/7432 – Bryan Oakley Aug 22 '17 at 14:16
  • I have no idea what some things do, like "class Frames (object)" or "def __init __ (self):". I'm assimilating this slowly, but it's frustrating. My program has 6500 lines, and I looked like I still do not understand it. – leandurus Aug 22 '17 at 14:19
  • There is already a question with an accepted answer for how to add a scrollbar to a grid of widgets. This question will likely be closed as a duplicate unless you can reword your question to show us what you've tried and why it failed. – Bryan Oakley Aug 22 '17 at 14:35
  • Ok! Wait need time – leandurus Aug 22 '17 at 14:42
  • progress, but still don't work – leandurus Aug 22 '17 at 16:38
  • i'm stoped in: creating a frame to inserto to canvas – leandurus Aug 22 '17 at 16:45

1 Answers1

2

Ok, working now! This post save me. Python Tkinter Canvas Scrollbar with Grid

from tkinter import *
import sqlite3
from tkinter.ttk import Combobox


mFrame = Tk()
mFrame.geometry("1300x775")
mFrame.configure(background="Gray")
mFrame.columnconfigure(0, weight=1)
mFrame.rowconfigure(0, weight=1)

frame_canvas = Frame(mFrame)
frame_canvas.grid(row=0, column=0, sticky='news')

Can1 = Canvas(frame_canvas, width=2000, height=2000)
Can1.grid(row=0, column=0)

vsbar = Scrollbar(frame_canvas, orient="vertical", command=Can1.yview)
vsbar.grid(row=0, column=1, sticky='ns')
Can1.configure(yscrollcommand=vsbar.set)

janela = Frame(Can1)
Can1.create_window((0,0), window=janela,anchor='nw')

class Frames(object):
    def __init__(self):
        pass

    def main_frame(self, janela):

    def Antunes_frame(self):

app = Frames()
app.main_frame(janela)
janela.mainloop()

mFrame.mainloop()
leandurus
  • 25
  • 5