0

Im trying to get my scrollbar to scroll, I've tried so many different commands and codes and none of them seem to work for me for some reason I can't understand. If I try adding a command like yview or yscrollcommand, then the text dissapears and it still doesnt scroll.

from tkinter import *
from functools import partial
import tkinter as tk

words = ["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test",
         "test", "test", "test", "test""test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test"]


def validateLogin(password):
    print(password.get())
    if password.get() == "test":
        master = Tk()
        master.state('zoomed')
        canvas_width = 1920
        canvas_height = 1080
        w = Canvas(master, width=canvas_width, height=canvas_height)
        scrollbar = Scrollbar(master)
        scrollbar.pack(side=RIGHT, fill=Y)
        count = 20
        for word in words:
            w.create_text(150, count, text=word)
            count += 20
        w.pack()
        tkWindow.destroy()
        mainloop()

    if password.get() != "test":
        Label(tkWindow, text="Wrong password!", fg='red').grid(row=5, column=2)


# window
tkWindow = Tk()
tkWindow.geometry('250x100')
tkWindow.title('Passwords')

# password label and password entry box
Label(tkWindow, text="Password").grid(row=1, column=0)
password = StringVar()
Entry(tkWindow, textvariable=password,
      show='*').grid(row=1, column=2)

validateLogin = partial(validateLogin, password)

# login button
Button(tkWindow, text="Login",
       command=validateLogin).grid(row=4, column=2)

tkWindow.mainloop()

Axsor
  • 69
  • 6
  • What are you trying to scroll? You can't scroll a frame of labels. I don't see any scrollable widgets in your code. Does this answer your question? [Adding a scrollbar to a group of widgets in Tkinter](https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter/3092341#3092341) Though, you might be better off using a `Text` widget. – Bryan Oakley Sep 18 '20 at 21:52
  • @BryanOakley So if i make it into a canvas I should be able to scroll? Or do I have to make like a Listbox type thing for it to scroll? – Axsor Sep 18 '20 at 21:57
  • 1
    You can use a canvas, as long as the things you want to scroll are canvas items. You can't add items to the canvas with `pack`, `place`, or `grid` and expect them to scroll. – Bryan Oakley Sep 18 '20 at 22:14
  • @BryanOakley I made it into a canvas, can I now add a command and scroll it? Or do I have to do something else? – Axsor Sep 19 '20 at 09:50
  • 1
    Check this Answer https://stackoverflow.com/questions/7727804/tkinter-using-scrollbars-on-a-canvas – Arun K Sep 19 '20 at 10:15
  • @ArunK Thanks, that helped alot. But I still have a problem. When I used that code and replaced some things, it will only scroll about half way and half of the text is still missing. Do you want me to update the code or do you know a solution? – Axsor Sep 19 '20 at 10:38

0 Answers0