How to use anchor() in Tkinter to align my Labels to the left side and the Buttons to the right adjacent to the labels

191 Views Asked by At

I am using Tkinter module in python to set up a program window.

What I want to do? I want to use anchor() function to align all the labels in my code to the left and the buttons to the right. Also I want Item_1 to be at the same level as the Button_1 in the following code.

from tkinter import *
import pyglet

# Font for the entire File
pyglet.font.add_file('RINTIK SENDU.ttf')

# Creating a Main Window Function.
def MainWindow():
   
   startup_window.destroy()
   
   main_window = Tk()

   # Styling it.
   main_window.title('Swiss Tool Box')
   main_window.geometry('950x500')
   main_window.resizable(False,False)
   main_window.iconbitmap('swisstoollogo.ico')

   # Heading Frame
   Heading_Frame = Frame(main_window)
   Heading_Frame.pack()

   # Heading Label
   Heading_Label = Label(Heading_Frame, text='SWISS TOOL BOX', font=('RINTIK SENDU',32))
   Heading_Label.pack()

   About_Label = Label(Heading_Frame, text='This is Swiss Tool Box is used to perform different tasks you might want to do. \n This includes many kinds of programs. \n You can select the one you want from the list below.', font=('RINTIK SENDU',21))
   About_Label.pack()

   # Button FrameSet for selection along with Labels.
   Button_Item_Frame = Frame(main_window)
   Button_Item_Frame.pack()

   Item_1 = Label(Button_Item_Frame, text='Area Volume Calculator', font=('RINTIK SENDU',14))
   Item_1.pack(side = LEFT)
   Button_1 = Button(Button_Item_Frame, text='Click here to use AVC', font=('RINTIK SENDU',10), width=30)
   Button_1.pack(side = RIGHT)

   Item_2 = Label(Button_Item_Frame, text='Conversion from Decimal to Binary, HexaDecimal or Octal', font=('RINTIK SENDU',14))
   Item_2.pack(side = LEFT)
   Button_2 = Button(Button_Item_Frame, text='Click here to use CODBOH', font=('RINTIK SENDU', 10), width=30)
   Button_2.pack(side = RIGHT)
   
   Item_3 = Label(Button_Item_Frame, text='Random Password Generator', font=('RINTIK SENDU',14))
   Item_3.pack(side = LEFT)
   Button_3 = Button(Button_Item_Frame, text='Click here to use RPG', font=('RINTIK SENDU',10), width=30)
   Button_3.pack(side = RIGHT)
   
   Item_4 = Label(Button_Item_Frame, text='Scientific Calculator', font=('RINTIK SENDU',14))
   Item_4.pack(side = LEFT)
   Button_4 = Button(Button_Item_Frame, text='Click here to use SC', font=('RINTIK SENDU',10), width=30)
   Button_4.pack(side = RIGHT)
   
   Item_5 = Label(Button_Item_Frame, text='Secret Code Encoder', font=('RINTIK SENDU',14))
   Item_5.pack(side = LEFT)
   Button_5 = Button(Button_Item_Frame, text='Click here to use SCE', font=('RINTIK SENDU',10), width=30)
   Button_5.pack(side = RIGHT)
   
   Item_6 = Label(Button_Item_Frame, text='Secret Code Decoder', font=('RINTIK SENDU',14))
   Item_6.pack(side = LEFT)
   Button_6 = Button(Button_Item_Frame, text='Click here to use SCD', font=('RINTIK SENDU',10), width=30)
   Button_6.pack(side = RIGHT)

   Item_7 = Label(Button_Item_Frame, text='Word Spammer', font=('RINTIK SENDU',14))
   Item_7.pack(side = LEFT)
   Button_7 = Button(Button_Item_Frame, text='Click here to use WS', font=('RINTIK SENDU', 10), width=30)
   Button_7.pack(side = RIGHT)

   Item_8 = Label(Button_Item_Frame, text='YouTube Video Downloader', font=('RINTIK SENDU',14))
   Item_8.pack(side = LEFT)
   Button_8 = Button(Button_Item_Frame, text='Click here to use YTVD', font=('RINTIK SENDU',10), width=30)
   Button_8.pack(side = RIGHT)
   #-----------------------------------------------------------------------------------------------------------------

   main_window.mainloop()

#---------------------------------------------------------------------------------------------------------------------
# Creating a Window to start the program.
startup_window = Tk()

startup_window.title('Swiss Tool Box')
startup_window.geometry('650x300')
startup_window.resizable(False, False)
startup_window.iconbitmap('swisstoollogo.ico')

Info_of_Button_Label = Label(startup_window, text='The button below will start up the Swiss Tool Box for you to use.', font=('RINTIK SENDU',18))
Info_of_Button_Label.pack()

startup_button = Button(startup_window,text='Click Me!', command=MainWindow, font=('RINTIK SENDU',12))
startup_button.pack()

startup_window.mainloop()
#---------------------------------------------------------------------------------------------------------------------

So this is my code and the output that is not favorable is attached. Please help me with this problem.

The Unfavorable Output

0

There are 0 best solutions below