-1

I am trying to create a calculator that takes in the row and column number in an excel file and calculates either the sum or difference for the two cells. I am trying to use Tkinter in python to develop the GUI. But I am facing an issue, i.e., the label.pack() doesn't display anything on my root window. I'm sharing my code below, please let me know what I am doing wrong.

import tkinter as tk
from tkinter import ttk

def main():
    print('Hello World!')
    root = tk.Tk()
    root.geometry('500x500')
    root.title('Celly_Cally')

    rowLabel = tk.Label(root, text="Row")
    rowLabel.pack(side = LEFT)
    root.mainloop()

if __name__ == "__main__":
    main()

1 Answers1

0

Neither you have defined LEFT nor imported it. Either replace it with str 'left'

import tkinter as tk
from tkinter import ttk

def main():
    print('Hello World!')
    root = tk.Tk()
    root.geometry('500x500')
    root.title('Celly_Cally')

    rowLabel = tk.Label(root, text="Row")
    rowLabel.pack(side = 'left')
    #OR also use this way(below) if you don't wnat to import one by one
    #rowLabel.pack(side = tk.LEFT)
    root.mainloop()

if __name__ == "__main__":
    main()

or import LEFT

import tkinter as tk
from tkinter import ttk,LEFT

def main():
    print('Hello World!')
    root = tk.Tk()
    root.geometry('500x500')
    root.title('Celly_Cally')

    rowLabel = tk.Label(root, text="Row")
    rowLabel.pack(side = LEFT)
    root.mainloop()

if __name__ == "__main__":
    main()
Bibhav
  • 1,579
  • 1
  • 5
  • 18
  • or you could also use, from Tkinter import * and then keep using (side = LEFT) – PandaSurge May 03 '23 at 04:34
  • `import *` is helpful but not recommended. Read [`about it`](https://stackoverflow.com/questions/2386714/why-is-import-bad). `tk.LEFT` would be better if you don't want to import let's say 10-20 of them – Bibhav May 03 '23 at 04:41