import tkinter as tk
from tkinter import *
from tkinter import ttk
from PIL import Image,ImageTk
class App(tk.Frame):
def __init__(self, parent,*args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.Frame = ttk.Frame(self.parent)
tk.Text.__init__(self, self.Frame, width=1, height=1)
self.winfo_toplevel().title("Periodic Table of the Elements")
self.topLabel = tk.Label(self, text="Click the element", font=20)
self.topLabel.grid(row=0, column=0, columnspan=18)
self.__initWidget()
self.infoLine = tk.Label(self, text="", justify='left')
self.infoLine.grid(row=24, column=0, columnspan=10, rowspan=4)
#self.mainloop() #Comment or remove it
def scro(self,parent, *args,**kwargs):
self._y_scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
self._text_widget = tk.Text(self, yscrollcommand=self._y_scrollbar.set, *args, **kwargs)
self._text_widget.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
# Replaces Label at the top with the name of whichever element tk.Button was pressed
def name(self, text):
self.topLabel.config(text=text)
# Displays information on the element of whichever element tk.Button was pressed
def info(self, text):
self.infoLine.config(text=text)
def scro(self):
root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill = Y )
mylist.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = mylist.yview )
def __initWidget(self):
self.Frame.grid(sticky="NSEW")
self.ScrollbarY = ttk.Scrollbar(self.Frame, orient="vertical",command=self.yview)
self.configure(yscrollcommand=self.ScrollbarY.set)
self.grid(column=0, row=0, sticky="NSEW")
self.ScrollbarY.grid(column=1, row=0, sticky="NS")
self.Frame.columnconfigure(0, weight=1)
self.Frame.rowconfigure(0, weight=1)
# Creates an instance of 'app' class
def main():
root = tk.Toplevel()
a = App(root)
a.grid(row=0, column=0, sticky='')
a.mainloop()
# runs main function
if __name__ == "__main__":
main()
how do i add scrollbars into this, i have cut some code out, mainly the loops which add elements, everything else is still there. i have tried various things and i can't seem to get it to work.I have tried packing it in the def init but that didn't work as one cannot use grid and pack together, i have also tried making a function, which is shown here as well, but that doesn't work.