0

I'm creating a project for my school using tkinter which focuses on a Dental Clinic. The code that I've posted here opens a window which asks the patient to login or sign up. The function is working properly except the canvas part. When the function is executed; the labels, text fields and the buttons move out of the canvas that I've put in the root window as shown in the screenshot of the output. What changes should I make so that the labels, text fields and buttons are in the canvas and not out of it?

def patclick(self):
       root = Tk()
       root.title("INSERT DETAILS")
       c = Canvas(root, bg="#dfe3ee")
       c.grid()
       titlelabel = Label(root, text="Please Login to continue")
       titlelabel.grid(row=0, columnspan=2)
       patnamelabel = Label(root, text="Full Name")
       patnamelabel.grid(row=1, column=0, sticky=E)
       self.patnameentry = Entry(root)
       self.patnameentry.grid(row=1, column=1)
       patpwlabel = Label(root, text="Password")
       patpwlabel.grid(row=2, column=0, sticky=E)
       self.patpwentry = Entry(root, show='*')
       self.patpwentry.grid(row=2, column=1)
       patloginbutt = Button(root, text="Login")
       patloginbutt.grid(row=3, columnspan=2)
       newpatlabel = Label(root, text="New Patient?")
       newpatlabel.grid(row=4, columnspan=2)
       patsignupbutt = Button(root, text="Sign Up")
       patsignupbutt.grid(row=5, columnspan=2)

The output after the function is executed

  • 1
    What do you think the first parameter of the `Label` and `Entry` and `Button` constructor is? The one where you pass `root` as the argument? Could it be the parent in which the widget will be placed? – Aran-Fey Apr 06 '18 at 17:12

1 Answers1

1

Pass the widgets c instead of root as the first parameter, and they will be placed in it:

widget=Label(c, text='whatever')

Then, when you pass widget to a geometry manager, it will be in c.

Artemis
  • 2,553
  • 7
  • 21
  • 36