Python Forum
[Tkinter] Issue with calling a Class/Method in GUI File
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Issue with calling a Class/Method in GUI File
#4
Short update from my side.

Since I didnt thought that there were any mistakes while calling the other class, I rebuilded simply everything, with some basics functions like the login , webscraper and so on.

Everythig seems to work now.
I didnt changed too much. Actually Nearly nothing.

Here is a snippet of the working code, for documentation if anyone has a similar issue.

gui.py
from tkinter import *
from tkinter import ttk

from app import ThisIsATest
from api import app

class Window(Tk):
    def __init__(self):
        super(Window, self).__init__()

        self.title("Tkinter OOP Window")
        self.geometry('500x400')

        self.button = ttk.Button(text = "Click", command=self.clickMe)
        self.button.grid(column=0, row=0)

    def clickMe(self):
        # call of the class
        api = app()
        
window = Window()
window.mainloop()
api.py
class app():
    def __init__(self):
        
        self.session = requests.Session()
        self.config = {}
        self.loggedIn = False
          
        self.testMethod()


    def testMethod(self):
        print('Run test Meethod')
        self.getJsonFileContent('config') 
        print(self.config['username'])
        

# METHODS ==================================================================
# ================= getJsonFileContent() =================
    def getJsonFileContent(self, param):
        # read in config file
        print(param)
        if(param == 'config'):
            try:
                with open('config.json', 'r') as configFile:
                    self.config=json.load(configFile)
                    configFile.close()
                
                logger.info(" READ config File ")
            except:
                logger.warning("Could not read in config file")

        # elif not need right now  cookies saved in self.cookies !
        elif (param == 'cookies'):
            try:
                pass #  r+   for read and write !

            except:
                logger.warning("Could not read in cookies file")
# ================= END OF getJsonFileContent() =================
Output:
Run test Meethod config player1
Well kinda strange, but as long as its working, its fine for me ^^

Anyways thanks for reading
Reply


Messages In This Thread
RE: Issue with calling a Class/Method in GUI File - by Fre3k - Mar-08-2020, 12:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video [PyQt] Get a executable file (.exe) from a .py file add a promoted class in a QWidget MiguelonReyes 0 712 Oct-17-2023, 11:43 PM
Last Post: MiguelonReyes
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,250 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [PyQt] I get a name Name Error: when calling a method inside a class radoo 2 2,435 Jun-11-2020, 05:02 PM
Last Post: radoo
  [Kivy] How do I reference a method in another class? Exsul1 3 4,353 Mar-02-2020, 07:32 PM
Last Post: Exsul1
  [Tkinter] Call a class method from another (Tk GUI) class? Marbelous 3 6,310 Jan-15-2020, 06:55 PM
Last Post: Marbelous
  Problem In calling a Function from another python file of project vinod2810 7 5,460 Oct-05-2019, 01:09 PM
Last Post: ichabod801
  Issue while importing variable from one file to other mamta_parida 14 6,457 Aug-29-2018, 11:40 AM
Last Post: mamta_parida
  [Tkinter] Class with text widget method AeranicusCascadia 3 7,849 Nov-14-2017, 11:33 PM
Last Post: AeranicusCascadia
  How to define a method in a class 1885 2 4,715 Oct-29-2017, 02:00 AM
Last Post: wavic
  [PyQt] How to put class method into new module? California 0 2,968 Jan-18-2017, 04:05 PM
Last Post: California

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020