WHAT DO I WANT TO GET? If the condition of the second.py file is true then "ok" will be printed in the textbox of the main.py file. If the confition is False, then "No" will be printed in the same textbox.
main.py is a file that is opened by the Home.py file. So initially there is the Home.py file which opens the main.py file inside it. The main.py file executes the second.py file. I only posted the main and second file, because the main file opens correctly in the home file
Home.py > main.py > second.py
In the main.py file I have a textobox and a button. To be precise, they are both in a class of the main file, but in the code I carry only the minimum necessary for the example.By clicking on the button, I would like to import the code located in another class of another file (second.py file). The code of the secondary.py file is used to generate text (with conditions) to be printed in the textobox of the main.py file. It's a simple case, but something is wrong.
The error is:
TypeError: __init__() missing 1 required positional argument: 'master'
Main.py
from tkinter import *
from tkinter import ttk
import tkinter as tk
class Home(tk.Frame): #update
def __init__(self, master): #update
super().__init__(master, **kw) #update
#class import from other file
from Folder.Folder2 import second
k = second.Print
#i want to print the output here
self.textobox = tk.Text(master, width=33, height=10, font=('helvetic', 12))
self.textobox.place(x=30, y=40)
self.button = Button(master, text="Ok", command= lambda: [one_function(), two_function()])
self.button.pack()
second.py
import sqlite3
class Print:
def __init__(self, master, **kw):
super().__init__(master, **kw)
self.conn = sqlite3.connect('...')
self.cursor = conn.cursor()
self.cursor.execute('SELECT x, y FROM Table')
self.element = cursor.fetchone()
self.cursor.execute("SELECT day FROM quantity")
self.day = cursor.fetchone()
#condition to print text in the textbox of the main.py file
if self.day == "Monday" and (self.element[0]) >= (self.element[1]):
textobox.insert(tk.END, "ok")
else:
textobox.insert(tk.END, "no")
The database is very simple:
CREATE TABLE "Table" (
"id" INTEGER,
"x" INTEGER, #for example 23
"y" INTEGER, #for example 12
PRIMARY KEY("id")
);
CREATE TABLE "quantity" (
"id" INTEGER,
"day" INTEGER, #for example Monday
PRIMARY KEY("id")
);