Python Forum
Improving my understanding of functions and methods
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Improving my understanding of functions and methods
#3
This is the complaint from pylint. Im re-working the scrpits to get rid of it. Seems adding classes do the trick.
Output:
************* Module test R: 91, 0: Too many instance attributes (11/7) (too-many-instance-attributes) ------------------------------------------------------------------ Your code has been rated at 9.91/10 (previous run: 9.91/10, +0.00)
class MainWindow:
    '''Docstring'''

    def __init__(self):
        self.root_window()
        self.container_frames()
        self.left_inner_frame()
        self.right_inner_frame()
        self.logo()
        self.show_footer()

    def root_window(self):
        '''Docstring'''
        self.root = ttk.Frame()
        self.root.grid_columnconfigure(0, weight=1)
        self.root.grid_rowconfigure(0, weight=1)

    def container_frames(self):
        '''Doc'''
        self.logo_frame = ttk.Frame(self.root)
        self.logo_frame.grid(column=0, row=0, sticky='new')
        self.logo_frame.grid_columnconfigure(0, weight=3)

        self.letter_menu_frame = ttk.Frame(self.root, relief='raised', padding=5)
        self.letter_menu_frame.grid(column=0, row=1, sticky='new')
        for i in range(26):
            self.letter_menu_frame.grid_columnconfigure(i, weight=3)

        self.multigrid_frame = ttk.Frame(self.root)
        self.multigrid_frame.grid(column=0, row=2, sticky='nw')
        self.multigrid_frame.grid_columnconfigure(0, weight=3)

        self.footer_frame = ttk.Frame(self.root)
        self.footer_frame.grid(column=0, row=3, sticky='new')
        self.footer_frame.grid_columnconfigure(0, weight=3)

    def left_inner_frame(self):
        '''Doc'''

        self.menu_title_frame = ttk.Frame(self.multigrid_frame)
        self.menu_title_frame.grid(column=0, row=0, sticky='nsw')
        self.menu_title_frame.grid_columnconfigure(0, weight=3)
        self.menu_title_frame.grid_rowconfigure(0, weight=3)

    def right_inner_frame(self):
        '''Doc'''

        self.get_recipe_frame = ttk.Frame(self.multigrid_frame)
        self.get_recipe_frame.grid(column=1, row=0, sticky='nsw')
        self.get_recipe_frame.grid_columnconfigure(0, weight=3)
        self.get_recipe_frame.grid_rowconfigure(0, weight=3)

    def logo(self):
        '''Docstring'''

        self.imgfile = tk.PhotoImage(file='/home/johnny/Desktop/play/cookbook_logo.png')
        self.img_logo = ttk.Label(self.logo_frame, image=self.imgfile, anchor='n')
        self.img_logo.grid(column=0, row=0, sticky='new')

    def show_footer(self):
        '''Docstring'''

        self.style = ttk.Style()
        self.style.map('my_footer.TLabel')
        self.style.configure('my_footer.TLabel', \
        foreground='blue', font=('Sans', 9, 'normal'), padding=8, border=2)

        self.footer = ttk.Button(self.footer_frame, \
        text='Register @ Johnny\'s CookBook', \
        style='my_footer.TLabel', cursor='hand2', command=web)

        self.footer.grid(column=0, row=0, sticky='n')
        self.footer.grid_columnconfigure(0, weight=3)

def main():
    '''Socstring'''
    root = tk.Tk()
    root.title('Johnny\'s CookBook')
    imgfile = tk.PhotoImage(file='/home/johnny/Desktop/play/cookbook_logo.png')
    root.configure(width=imgfile.width(), border=5, relief='ridge')
    root.resizable(width=False, height=False)
    MainWindow()
    root.mainloop()

if __name__ == '__main__':
    main()

I disabled the message with # pylint: disable=R0902

Was going to do it in the configuration but decided that someone though 7 was enough in coding?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Improving my understanding of functions and methods - by menator01 - Apr-24-2020, 06:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  functions/methods menator01 2 1,693 Oct-02-2021, 07:37 PM
Last Post: menator01
  Need help improving function that reads file into list of tuples t4keheart 6 3,190 Nov-03-2020, 04:58 AM
Last Post: ndc85430
  Improving code to autorename if filename exists Den0st 5 3,086 Sep-23-2019, 07:53 AM
Last Post: wavic
  Need help understanding a couple of functions (encrypt,decrypt, int_to_bytes) xoani 0 2,052 Jun-09-2019, 03:25 PM
Last Post: xoani
  Improving bot SheeppOSU 0 30,947 Jun-01-2019, 08:06 PM
Last Post: SheeppOSU
  How to find functions or methods in a module? deepakdeshp 8 4,447 May-23-2019, 09:36 AM
Last Post: DeaD_EyE
  Is there a way of improving this leaderboard system? Zelpha 2 3,973 Feb-11-2019, 06:32 PM
Last Post: ichabod801
  i have problems understanding 2 functions,look for help. Tony 2 2,703 Dec-05-2018, 12:35 PM
Last Post: Tony
  Help in understanding scope of dictionaries and lists passed to recursive functions barles 2 3,300 Aug-11-2018, 06:45 PM
Last Post: barles
  Improving Efficiency of SVM by various available kernels Sachtech 0 2,155 Apr-09-2018, 07:29 AM
Last Post: Sachtech

Forum Jump:

User Panel Messages

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