How Do I Print An Array In Different Lines In GUI Window?
I want to display the data of the array in GUI in different lines. This is the code. import tkinter as tk window = tk.Tk() window.configure(background='white') ws = window.winfo_s
Solution 1:
You can also try this:
op = ("Hello", "Good Morning", "Good Evening", "Good Night", "Bye")
def applytoLabel():
n = len(op)
element = ''
for i in range(n):
element = element + op[i]+'\n'
return element
l9 = tk.Label(canvas, text=applytoLabel(), font= "calibri 13", bg="white")
canvas.create_window(33,33, window=l9, anchor=tk.NW)
output:
Full Code:
import tkinter as tk
window = tk.Tk()
window.configure(background='white')
ws = window.winfo_screenwidth()
hs = window.winfo_screenheight()
w = 200 # width for the Tk root
h = 500 # height for the Tk root
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
window.geometry('%dx%d+%d+%d' % (w, h, x, y))
canvas = tk.Canvas(window, bg="white", width=980, height=580, highlightthickness=0)
canvas.pack()
canvas_scroll = tk.Scrollbar(canvas, command=canvas.yview)
canvas_scroll.place(relx=1, rely=0, relheight=1, anchor=tk.NE)
canvas.configure(yscrollcommand=canvas_scroll.set, scrollregion=())
op = ("Hello", "Good Morning", "Good Evening", "Good Night", "Bye")
def applytoLabel():
n = len(op)
element = ''
for i in range(n):
element = element + op[i]+'\n'
return element
l9 = tk.Label(canvas, text=applytoLabel(), font= "calibri 13", bg="white")
canvas.create_window(33,33, window=l9, anchor=tk.NW)
window.mainloop()
Post a Comment for "How Do I Print An Array In Different Lines In GUI Window?"