Python Forum
how to use getter as argument in function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to use getter as argument in function
#4
Sorry I guess I only vaguely stated my question. I was having trouble bringing my getter value through my new_setting function.

But I found my issue. Weird combining of syntax and misplaced lines, felt like I was so far away but fairly simple fix.

Thanks Larz, I do like the idea of less code! Plus it's all my standalone program so I don't have to interface with other code so I could truly write it any way that works.

And thanks again Dean, you explain thoroughly and show great examples. I think you nailed it in your second sentence, defining rinse where my new setting is called.

For anyone who finds themselves stuck in this learning curve here's my mistakes and simple solution:
from tkinter import *

class Settings:
    def __init__(self):
        self._rinse = 16


    @property
    def rinse(self):
        return self._rinse

    @rinse.setter
    def rinse(self, value):
        self._rinse = value


settingsPage = Tk()
settingsPage.geometry("1024x600")


def new_setting(getter_name, row):
    #s = Settings()     # I mistakenly thought the instance should be created here and combined with getter_name
    value_lbl = Label(text=getter_name, master=settingsPage)  # previously s.getter_name  
    value_lbl.grid(row=row, column=0)

s = Settings()       # the correct place for the instance
new_setting(s.rinse, 1)   # previously: new_setting(rinse, 1)

settingsPage.mainloop()
Reply


Messages In This Thread
RE: how to use getter as argument in function - by nanok66 - May-13-2020, 09:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  question about using setter, getter and _ akbarza 4 687 Dec-28-2023, 09:43 PM
Last Post: deanhystad
  mutable argument in function definition akbarza 1 480 Dec-15-2023, 02:00 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,089 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,860 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Regex - Pass Flags as a function argument? muzikman 6 3,591 Sep-06-2021, 03:43 PM
Last Post: muzikman
  How to use a tuple as an argument of a function zarox 5 3,606 Nov-14-2020, 08:02 PM
Last Post: buran
  calling a function and argument in an input phillup7 3 2,613 Oct-25-2020, 02:12 PM
Last Post: jefsummers
  Passing argument from top-level function to embedded function JaneTan 2 2,262 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  return string from function with one argument jamie_01 2 2,195 May-28-2020, 11:07 PM
Last Post: menator01
  Getter/Setter : get parent attribute, but no Getter/Setter in parent nboweb 2 2,977 May-11-2020, 07:22 PM
Last Post: nboweb

Forum Jump:

User Panel Messages

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