Jul-04-2020, 08:38 AM
(This post was last modified: Jul-04-2020, 08:50 AM by deanhystad.)
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:
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.
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.