Reputation: 13
Have been trying to add a scrollbar to my GUI through TKinter but am running into issues. The code is running into an error stating that the name 'frame' is not defined, when it should be since all of tkinter has been imported.
import tkinter as tk
data = {'Seller': 'paranoya', 'Link': 'https://forum.exploit[.]in/topic/214240/', 'Date Posted': 1665878400000, 'Original': 'Тип доступа: VPN-RDP\nВсе доступы валид.\nВсегда готов к гаранту!\nЧтобы узнать больше о доступе пиши в ПМ\n\nNew Zealand/7 kk$/Answering service/Local Admin- 100$', 'Translated': 'Access type: VPN-RDP\nAll accesses are valid.\nAlways ready for a guarantor!\nTo learn more about access, write to the PM\n\nNew Zealand/7 kk$/Answering service/Local Admin- 100$'}
input_data = {'Username': None, 'Medium': None, 'Date Posted': None, 'Country': None, 'Sector': None, 'Revenue': None, 'Employees': None, 'Start': None, 'Step/War': None, 'Price/Blitz': None, 'Analysis': None, 'Additional info': None, 'Date Sold': None, 'Buyer': None}
window = tk.Tk()
window.geometry('1000x1000')
window.title("JSON Sorting")
window.configure(bg='#EEF1DB', padx=500, pady=30)
# Attempting to create scrollbar for whole window
main_frame = Frame(window)
main_frame.pack(fill=tk.BOTH, expand=1)
my_canvas = Canvas(main_frame)
my_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
scroll = tk.Scrollbar(main_frame, orient=tk.VERTICAL, command=my_canvas.yview)
scroll.pack(side=tk.RIGHT, fill=tk.Y)
my_canvas.configure(yscrollcommand=scroll.set)
my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox('all')))
second_frame = Frame(my_canvas)
my_canvas.create_window((0,0), window=second_frame, anchor='nw')
# Adding other info to GUI
label = tk.Label(text='Info pulled from JSON')
label.grid(column=2, row=0)
label = tk.Label(text='Manual Filtering/Ordering info')
label.grid(column=4, row=0)
c = 1
for x in data:
info = tk.Label(text=x)
info.grid(column=1, row=c)
txtbox = tk.Text(second_frame)
txtbox.configure(height=8, pady=10)
txtbox.grid(column=2, row=c)
txtbox.insert(tk.INSERT, data[x])
c+=1
c = 1
for x in input_data:
label = tk.Label(text=x)
label.grid(column=3, row=c)
txtbox = tk.Text(second_frame)
txtbox.configure(height=8, pady=10)
txtbox.grid(column=4, row=c)
c+=1
window.mainloop()
During execution, I get this error
File "C:\Users\volks\Desktop\Python\Main.py", line 6, in from tkinter import canvas ImportError: cannot import name 'canvas' from 'tkinter' (C:\Users\volks\anaconda3\lib\tkinter_init_.py)
What is the problem?
Upvotes: 0
Views: 267
Reputation: 27
your write :
import tkinter as tk
so you should write widgets like this: tk.widget
Upvotes: 1