0

I'm creating UI of a form using Tkinter in Python2 where IDE is PyCharm.

Following is the code for the reference:-

from Tkinter import *;

root = Tk()

root.geometry("400x100")

#adding the header label of the tool.
myheaderTitle = Label(root,text="myForm",bg="lime green",font="Calibri 16 bold",width="400")
myheaderTitle.pack()

button_1 = Button(root,text="Select File")
button_1.grid(row=0,column=0)
root.mainloop()

I'm successful in running the above code, but the form is not visible whenever I add below two lines of code.

button_1 = Button(root,text="Select File")
button_1.grid(row=0,column=0)

What could be the problem with these lines?

BBRK
  • 102
  • 1
  • 1
  • 12

1 Answers1

0

Based on @FrainBr33z3 and @acw1668 comments, I was able to create my UI using the grid system in Python2.

I used following reference link(s) to understand the grid system.

Below is the code for reference: -

from Tkinter import *;

root = Tk()

root.geometry("400x100")

#adding the header label of the tool.
myheaderTitle = Label(root,text="myForm",bg="lime green",font="Calibri 16 bold",width="400")
myheaderTitle.grid(row=0,column=0,sticky=(N, S, W, E),padx=5, pady=5,columnspan=2)

button_1 = Button(root,text="Select File")
button_1.grid(row=1,column=0,sticky=(N, S, W, E),padx=5, pady=5)

button_2 = Button(root,text="Select Another File")
button_2.grid(row=1,column=0,sticky=(N, S, W, E),padx=5, pady=5)

root.grid_columnconfigure(0,weight=1)
root.grid_rowconfigure(0,weight=1)
root.grid_columnconfigure(1,weight=1)
root.mainloop()

Hope this helps someone.

BBRK
  • 102
  • 1
  • 1
  • 12