Wednesday 13 May 2020

Python Tkinter GUI: Add Scrollbar to Text Box || Insert Text Into Text B...

Python Tkinter GUI: Add Scrollbar to Text Box || Insert Text Into ...

Python Tkinter GUI: Add Scrollbar to Text Box || Insert Text Into Text Box | Python tk


Code:

import tkinter as tk
Window = tk.Tk()
Window.geometry("250x200")
frame = tk.Frame(Window, pady=10, padx=10)
frame.grid(row=0, column=0, sticky="nsew")
text = tk.Text(frame, width=25, height=6, font=("Times New Roman", 12))
text.grid(row=0, column=0, rowspan=6, columnspan=2, pady=5, padx=5)
scrollbar = tk.Scrollbar(frame, command=text.yview)
text['yscroll'] = scrollbar.set
scrollbar.grid(row=0, column=2, rowspan=6, sticky="ns")
quote =
"""HAMLET: To be, or not to be--that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune Or to take arms against a sea of troubles And by opposing end them. To die, to sleep-- No more--"""
text.insert(tk.INSERT, quote)
button = tk.Button(frame, text="Close", fg="white", bg="red", command=exit)
button.grid(row=7, column=1)
Window.mainloop()



#Python
#Tkinter
#GUI
#Text_Box
#Scrollbar
#Insert_Text



No comments:

Post a Comment