I have code which so far was using purely grid strcuture to place buttons and text, but this did not allow me to place a vertical scrollbar. I need to change my code to put it in a canvas which has a frame, and then the frame needs to buttons+text and canvas needs to have a vertical scroll bar.
The code is as follows:
import tkinter as tk
from pixelregex import regex
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.num_snippets = 1
self.initialize()
def initialize(self):
self.grid()
self.entryVariable = tk.StringVar()
# Just some buttons on the window
button_start = tk.Button(self, text=u"Start", command=self.onStart)
button_start.grid(row=0, column=0, sticky="EW")
button_reset = tk.Button(self, text=u"Quit", command=self.onReset)
button_reset.grid(row=0, column=1, sticky="EW")
self.entry = tk.Entry(self, textvariable=self.entryVariable)
self.entry.grid(row=0, column=2, sticky="EW")
self.columnconfigure(1, weight=1)
def onStart(self):
# Get the value entered in the Entry widget
dim = self.entryVariable.get()
try:
dim = int(dim)
except ValueError:
dim = 2 # Default
print("Non integral dimension as input. Setting it to two ..")
# FUnction that returns a list having 4 strings
reg = regex.getRegex(dim)
row_num = str(self.num_snippets)
snippet_id = tk.Label(self, text=row_num, anchor="w", fg="blue", bg="white")
snippet_id.grid(column=0, row=self.num_snippets, columnspan=1, sticky='EW')
text = tk.Text(self, width=100, height=10)
text.grid(row=self.num_snippets, column=1, columnspan=2, sticky="EW")
input_string = "Top: " + reg[0] + "\n\n" + "Bottom: " + reg[1] + "\n\n" + "Left: " + reg[
2] + "\n\n" + "Right: " + reg[3] + "\n\n"
text.insert('1.0', input_string)
self.num_snippets += 1
def onReset(self):
self.destroy()
pass
I've tried making a canvas, putting a frame in it, using that frame to insert buttons using grid() but the canvas remains empty! I also need to insert a vertical scrollbar.
Help is highly appreciated.
Textwidget? - Bryan Oakley