So you got a partial answer already, but there's a number of things I want to point out.
First, you can simply use place.get() as any other int/str/whatever. So you can just use it directly in your if statements. Using a single choice = place.get() can be used as well, and this would make sense if you need to access the value a gazillion times in the function. However,
Second, the if/elif/else is no longer needed. Starting from python 3.10 there's a case/switch statement available (took way too long for that to be implemented, but that's a different can of worms).
There's one weird drawback in this though, the match/case statement doesn't like direct variables, and as per this answer there's a relatively easy fix. Be sure to also change the relevant assignment in your combobox.
The if/elif/else statements in the choose() function don't make sense, and the 8 place functions make even less sense. Code duplication is really an antipattern that can very easily lead to code spaghetti and increases the chances of bugs.
You're using the value from place as the row so you can directly pass that to the function that sets the row for the widget. Or you could just use the place.get() directly in that function.
Another thing to take into account is that you're not keeping track of the actual placed widgets. There's nothing stopping you from placing 9001 different widgets in the same row. This is likely unwanted behavior, so you will need to keep track of the widget. So, create a list to hold the widgets. This also solves the problem that you cannot access the created widgets easily, as they are not assigned to a variable directly. Whether this is intended or not is not for me to determine.
### NO CHANGE HERE
from tkinter import *
from tkinter import ttk
root = Tk()
frame = ttk.Frame(root, style="color.TFrame")
s = ttk.Style()
s.configure("color.TFrame", background="black", borderwidth=5, relief="sunken")
root.title("Widget Manipulator")
frame.grid(column=0, row=0)
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
### CODE BELOW CHANGES
# this link explains the needed usage of a class
# https://stackoverflow.com/a/66159622/9267296
class WidgetTypes:
a = "Spinbox"
b = "Entrybox"
c = "Checkbox"
d = "RadioButton"
e = "Combobox"
f = "Listbox"
g = "Scale"
h = "Progressbar"
# create a list with 8*None to prevent out of bound errors
# Since lists are zero-indexed, we put a dummy value in index 0
# in prod, this should be another None to reduce resource usage
widget_list = ["0-indexed workaround", None, None, None, None, None, None, None, None]
def choose():
if place.get() >= 1 and place.get() <= 8:
place_widget(place.get())
else:
placetext.set("Please choose an Option for the place")
def place_widget(choice: int):
# this only works in python 3.10+
# check if widget type is selected and also if row
# is already existing widget and destroy if needed
# this will prevent memory leaks (I think)
if widget.get() != "" and widget_list[choice] != None:
widget_list[choice].destroy()
match widget.get():
case WidgetTypes.a:
widget_list[choice] = ttk.Spinbox()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.b:
widget_list[choice] = ttk.Entry()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.c:
widget_list[choice] = ttk.Checkbutton()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.d:
widget_list[choice] = ttk.Radiobutton()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.e:
widget_list[choice] = ttk.Combobox()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.f:
widget_list[choice] = Listbox()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.g:
widget_list[choice] = ttk.Scale()
widget_list[choice].grid(column=1, row=choice)
case WidgetTypes.h:
widget_list[choice] = ttk.Progressbar()
widget_list[choice].grid(column=1, row=choice)
case _: # this is the final catch-all statement.
widgettext.set("please enter widget")
# Widgets
place = IntVar()
widget = StringVar()
placetext = StringVar()
widgettext = StringVar()
Label(frame, textvariable=placetext).grid(column=2, row=1)
Label(frame, textvariable=widgettext).grid(column=0, row=1)
Button(frame, text="Change", command=choose).grid(column=1, row=0)
ttk.Combobox(
frame,
textvariable=widget,
values=(
WidgetTypes.a,
WidgetTypes.b,
WidgetTypes.c,
WidgetTypes.d,
WidgetTypes.e,
WidgetTypes.f,
WidgetTypes.g,
WidgetTypes.h,
),
).grid(column=0, row=0)
ttk.Combobox(frame, textvariable=place, values=(1, 2, 3, 4, 5, 6, 7, 8)).grid(
column=2, row=0
)
root.mainloop()