#๐ i have a question in tkinter
20 messages ยท Page 1 of 1 (latest)
@faint shore
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
i want to know what *args, and **kwargs, mean?
im making a window in tkinter
using classes
*args and **kwargs are ways of accepting unlimited arguments in a function. By using it here, you're leaving the original class' signature intact
!kwargs
These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.
Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.
Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.
Use cases
- Decorators (see
/tag decorators) - Inheritance (overriding methods)
- Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
- Flexibility (writing functions that behave like
dict()orprint())
See /tag positional-keyword for information about positional and keyword arguments
Oh sweet
this basically lets you pass along the same expected parameters of the parent class to the child class
so they behave the same way
you could change it if you wanted to modify the behaviour
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.