Python Forum
[Tkinter] How to erase previous output from the canvas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to erase previous output from the canvas?
#3
Normally you would not create a canvas and fill it with windows to make a dialog window. Normally you wouldn't use a canvas at all. Typical tkinter dialog code looks more like this:
from tkinter import *
window = Tk()
window.title("My Wubdiw")
window.geometry('350x200')
lbl = Label(window, text="Hello")
lbl.grid(column=0, row=0)
btn = Button(window, text="Click Me")
btn.grid(column=1, row=0)
window.mainloop()
Notice there is no explicit sizing and placement. That is left up to the grid layout manager.

You do need a canvas if you want scrollable content, but even then I would expect the canvas to scroll one window that contains a frame that contains all the controls to be scrolled. This lets you use layout management instead of explicit sizing and positioning. Generally scrolled regions are something you see in controls (long lists, multi-line text entries), not top level windows.

The reason your old label text remains when you enter new text is because the getInput function creates a new label that is drawn in the same place as the old. The first time you call getInput you have one label to display the entered text. The second time it is called you have two labels. If the first label is wider than the second you will see parts of the old label. Either you need to delete the old label, or reconfigure the old label to contain the new text.
Reply


Messages In This Thread
RE: How to erase previous output from the canvas? - by deanhystad - Jul-04-2020, 08:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 25,216 Jun-04-2019, 05:05 AM
Last Post: Gupi
  [Tkinter] output to canvas widget freakbot 2 10,002 Dec-01-2016, 12:24 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020