0

I am trying to read a text file which is very big and I need a Scale widget for that. So, I am using this code:

from Tkinter import *
tk = Tk()
tk.title("Report")
f = open("hola.txt", "r").read()
Label(tk, text=f).grid(row=0)
w = Scale(tk, from_=0, to=100)
w.pack()
tk.mainloop()

It's not opening the file. It's only showing me the scale, but this code opens file perfectly but isn't with the scale:

from Tkinter import *
tk = Tk()
tk.title("Vulnerability Report")
f = open("hola.txt", "r").read()
Label(tk, text=f).grid(row=0)
tk.mainloop()
finefoot
  • 9,914
  • 7
  • 59
  • 102
Alex
  • 31
  • 8

1 Answers1

1

I think, for this situation, if you want to read text from file, is better suited simple scrolllbar with listbox.

from Tkinter import *

root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
listbox = Listbox(root)
listbox.pack()
file = open('hola.txt', 'r').readlines()
for i in file:
    listbox.insert(END, i)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
mainloop()

If you want to edit, use other widget or more info, check http://effbot.org/zone/tkinter-scrollbar-patterns.htm

Sorry, if I misunderstood your question.

Foxpace
  • 114
  • 1
  • 5