0

Im trying to make a GUI calculator, a very basic one, it only has division, subtraction, addition, and multiplication. I use the Tkinter module. I make buttons, labels, and entry widgets, then display them with pack()function, everything is going smoothly, and then I change it to usegrid()` function to beautify things up. When I tested it, this message shows up

_tkinter.TclError: bad option "-row": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side

This is my full code

from tkinter import *


add_sign = "+"
sub_sign = "-"
tms_sign = "x"
div_sign = ":"

root = Tk()
operation_sign_string = StringVar()
operation_sign = Label(textvariable=operation_sign_string)
inputA = Entry(bd=3)
inputB = Entry(bd=3)


def add_onclick():
    operation_sign_string.set(add_sign)


def sub_onclick():
    operation_sign_string.set(sub_sign)


def tms_onclick():
    operation_sign_string.set(tms_sign)


def div_onclick():
    operation_sign_string.set(div_sign)


add = Button(text="+", command=add_onclick)
sub = Button(text="-", command=sub_onclick)
tms = Button(text="x", command=tms_onclick)
div = Button(text=":", command=div_onclick)

add.grid(column=1, row=2)
sub.grid(column=2, row=2)
tms.grid(column=3, row=2)
div.grid(column=4, row=2)
operation_sign.grid(column=2, row=1)
inputA.grid(column=1, row=1)
inputB.pack(column=3, row=1)

root.mainloop()

I tried only one thing, switching the order of the properties from grid(row=1 column=1) to grid(column=1, row=1). That chages the error from _tkinter.TclError: bad option "-row": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side to _tkinter.TclError: bad option "-column": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side

I have no clues whatsoever abouth why tkinter spits out this error.

1 Answers1

1

Like mentioned in comments you can't use row or column if you're using pack geometry manager. Those options belongs to the grid geo manager.

Line 43 should be changed to: inputB.grid(column=3, row=1)

from tkinter import *

add_sign = "+"
sub_sign = "-"
tms_sign = "x"
div_sign = ":"

root = Tk()
operation_sign_string = StringVar()
operation_sign = Label(textvariable=operation_sign_string)
inputA = Entry(bd=3)
inputB = Entry(bd=3)

def add_onclick():
    operation_sign_string.set(add_sign)

def sub_onclick():
    operation_sign_string.set(sub_sign)

def tms_onclick():
    operation_sign_string.set(tms_sign)

def div_onclick():
    operation_sign_string.set(div_sign)

add = Button(text="+", command=add_onclick)
sub = Button(text="-", command=sub_onclick)
tms = Button(text="x", command=tms_onclick)
div = Button(text=":", command=div_onclick)

add.grid(column=1, row=2)
sub.grid(column=2, row=2)
tms.grid(column=3, row=2)
div.grid(column=4, row=2)
operation_sign.grid(column=2, row=1)
inputA.grid(column=1, row=1)
inputB.grid(column=3, row=1)

root.mainloop()
Module_art
  • 999
  • 2
  • 9
  • 26