Home > Blockchain >  What's wrong with the Python tkinter code
What's wrong with the Python tkinter code

Time:06-07

I'm trying to make a schedule. Here, with the data I received by entry, the mineral selected in the optionmenu will be taken and compared with the values in the database, but the button function does not work exactly. The error it gives is: Typeerror: buttonfunction() missing 2 required positional arguments: 'variable' and 'entryvalue'. I couldn't figure out how to take the values into the function, and the other function doesn't give the program the value it assigns to the variable variable. I don't know how much I was able to tell, but I would appreciate it if you could help. https://www.technopat.net/sosyal/konu/python-kodundaki-hata-nedir.1994095/

CodePudding user response:

Well, your code works, but it was terribly formatted, and there are dots at the end of the lines that shouldn't be there.

Here - fixed it for ya.

from tkinter import *
import sqlite3
import os

# Main Program.
root = Tk()
root.title("Minerals and Vitamins")
width = 400
height = 240
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d %d %d" % (width, height, x, y))
root.resizable(0, 0)

dosya = "vt.sqlite"
dosya_mevcut = os.path.exists(dosya)

vt = sqlite3.connect(dosya)
im = vt.cursor()

mineral_datas = [
    ("Calcium", 8.5, 10.4, "Wheat flour - 40 mg", "Corn flour - 9 mg", "Rice - 20 mg"),
    ("Sodium", 136, 145, "9 mg in Hot Red Pepper", "7 mg in Avocado", "4 mg in Quince"),
    ("Iron", 60, 170, "Pumpkin seeds - 10 mg", "Pistachios - 4 mg", "Moon core - 7 mg"),
    (
        "Magnesium",
        2.0,
        2.7,
        "Pumpkin seeds - 10 mg",
        "Pistachios - 4 mg",
        "Moon core - 7 mg",
    ),
    (
        "Phosphorus",
        2.7,
        4.5,
        "Dried apricots - 108 mg",
        "Banana - 26 mg",
        "Grapes - 20 mg",
    ),
]

im.execute(
    """CREATE TABLE IF NOT EXISTS minerals
(name TEXT, min_value REEL, max_value REEL, food_1 TEXT, food_2 TEXT, food_3 TEXT)"""
)

if not dosya_mevcut:
    for data in mineral_datas:
        im.execute("""INSERT INTO minerals VALUES(?, ?, ?, ?, ?, ?)""", data)
        vt.commit()


def getv(variable):
    variable = varList.get()
    return variable


def buttonfunction(variable, entryvalue):
    last_value = int(entryvalue.get())
    if variable == "Calsium":
        im.execute("""SELECT * FROM minerals WHERE name = "Calcium" """)
        deger = im.fetchone()
        print(deger[1])
    if last_value < deger[1]:
        print("eksik")


# ==============================LABELS=========================================
hello_label = Label(root, text="Minerals and Vitamins", font=("MonoLisa", 15))
hello_label.pack(fill=X)

value_label = Label(root, text="Your Values: ", font=("MonoLisa", 15), bd=15)
value_label.place(x=15, y=60)

value_choose_label = Label(root, text="Your Chooses: ", font=("MonoLisa", 15), bd=15)
value_choose_label.place(x=15, y=110)

# ==============================ENTRY WIDGETS==================================
entryvalue = IntVar()
value_input = Entry(root, textvariable=entryvalue, font="MonoLisa")
value_input.place(x=165, y=78)

varList = StringVar(root)
varList.set("Please Choose")
choose_list = [
    "Calcium",
    "Sodium",
    "Iron",
    "Magnesium",
    "Phosphorus",
    "Potassium",
    "Zinc",
    "Copper",
    "Chromium",
    "Iodine",
    "Selenium",
    "Manganese",
    "Fluorine",
]

choose_menu = OptionMenu(root, varList, *choose_list, command=getv)
choose_menu.place(x=165, y=122)

submit_button = Button(
    root, text="Submit", font=("Calibri", 10), command=buttonfunction
)
submit_button.place(x=310, y=180)
# ==============================LOOP==================================
root.mainloop()

CodePudding user response:

you dont have given the paramters for button function. you can give the paramteres.you can edit and use this code;

submit_button = Button(root, text="Submit", font=("Calibri", 10), command= lambda: buttonfunction(variable, entryvalue))
  • Related