0

I am trying to develop a simple python tool using Tkinter.I have created 3 files and below is the code. The files are GUI.py

from tkinter import *
from tkinter.messagebox import *
import tkinter.ttk as ttk
import versionTab
import logclass

class GUI(Tk):
    def __init__(self, parent):
        self.parent = parent
        parent.title("Tool")
        parent.geometry('695x600+100+100')
        self.frame = Frame(parent,bd=5).grid()
        self.infoLabel = LabelFrame(self.frame,text="Information",height=100,width=100)
        self.version = versionTab.versionTab(self.infoLabel)
        self.infoLabel.grid(row=1,column=0,columnspan =2,padx=8,pady=2,sticky = W)

        self.logLabel = LabelFrame(self.frame,height=1000,width=1000)
        self.Log = logclass.debuglog(self.logLabel)
        self.logLabel.grid(row=4,column=0,columnspan =2,padx=8,pady=2,sticky = W)

root = Tk()
gui = GUI(root)
root.resizable(0,0)
root.mainloop()

The next file is versionTab.py

from tkinter import *
from tkinter.messagebox import *
import logclass

class versionTab():
    def __init__(self,frame):
        self.firmwareFrame =LabelFrame(frame,height=15,width=100)
        self.firmwareversion_B = Button(self.firmwareFrame, text=" Version",command= self.getFW).grid(row=0,column=0,padx=2,pady=5)
        self.versionText_Entry = Entry(self.firmwareFrame,width=10)
        self.versionText_Entry.configure(state ='readonly')
        self.versionText_Entry.grid(row=0,column=1,padx=4,pady=5)
        self.firmwareFrame.grid(row=1,column=0,columnspan =2,padx=2,pady=2,sticky = W)

    def getFW(self):
        logclass.debuglog.logst(self,"12344")

final file is logclass.py

from tkinter import *
import tkinter.ttk as ttk
from datetime import datetime

class debuglog():
    def __init__(self,frame):
        self.debuglog = LabelFrame(frame,text = "Log",height=15,width=100)
        self.log      = Text(self.debuglog,height = 20, width = 80)
        self.scrollb  = Scrollbar(self.debuglog, orient=VERTICAL)
        self.scrollb.config(command = self.log.yview) 
        self.log.config(yscrollcommand = self.scrollb.set)
        self.log.grid(column=0, row=0)
        self.scrollb.grid(column=1, row=0, sticky=W)
        self.debuglog.pack()

    def logst(self,msg, level=None):
        print('logclass')
        self.log.insert(insert('end', msg + '\n'))

    def exitWindow(self):

        print('exit..')

while I are running my GUI.py file I am able to generate the tool.The tool will display a simple button version.when I click the version button on tool its throwing the below error

versionTab.py", line 15, in getFW
    logclass.debuglog.logst(self)
TypeError: logst() missing 1 required positional argument: 'msg'

Could any one tell me why I am not able to call the logst from my versiontab file

1
  • The line in the error traceback does not match with the posted code for versionTab.py. Commented Dec 28, 2021 at 4:19

1 Answer 1

2

You seem to be attempting to call the method logst on the class debuglog. This will not work, as "logst" is not a static method. You would need to create an instance of debuglog in order to call the method logst on it.

I also do not understand why you are passing self to the logst function when you call it

In the constructor for the versionTab class, you could add self._logger = logclass.debuglog(), and then call self._logger.logst rather than logclass.debuglog.logst.

Perhaps look into the differences between static methods and non static methods?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.