Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [python-class]

For questions that relate to the use of classes as a language feature in Python.

python-class
0 votes
1 answer
39 views

How to inherit (from a parent class) dataclass field introspection functionality?

I have a parent dataclass, and various other classes will then extend this parent dataclass. Let's call these dataclasses DCs. In the example code below, see ParentDC, and an example ChildDC: from ...
bzm3r's user avatar
  • 3,842
0 votes
1 answer
29 views

Trying to center and uniformly space a 4x4 grid of entry widgets within a frame, within a frame class. What am I missing?

First up, I'm really pretty bad at OOP and tkinter/customtkinter and this is only my third project I've built with classes over straight functions, so please excuse my mess. I'm getting there, and ...
nannerpuss's user avatar
0 votes
2 answers
50 views

Python decorators with class methods

I want a decorator that I can use as both @decorator and decorator() with class methods, like this : def decorator_with_args(name): print(f'Hello {name} !') def decorator(func): def ...
Prasun Kumar Khan's user avatar
0 votes
0 answers
33 views

Having a problem with calling the class twice

import tkinter as tk import math,time,random from PIL import ImageTk, Image,ImageEnhance start_time = time.time() window = tk.Tk() window.geometry("300x300") canvas = tk.Canvas(window, ...
MeHocha 333's user avatar
1 vote
3 answers
69 views

How to display an image with classes in tkinter?

import tkinter as tk from PIL import ImageTk, Image window = tk.Tk() window.geometry("300x300") canvas = tk.Canvas(window, width=300, height=300,bg="red") canvas.pack() class ...
MeHocha 333's user avatar
0 votes
0 answers
108 views

OpenAI API upgrade from 0.28 to 1.x

I am trying to upgrade the OpenAI 0.28 version to 1.2.2. For doing that I defined the client and replaced the openai chatcompletion with client. Below is the constant file which will be used in the ...
Pushpendra Singh's user avatar
0 votes
1 answer
33 views

How can I substitute an imported python class in a .py file without modifying the file itself?

What I'd like to achieve is: b.py(might be in a third party package I cannot modify): from xxx import A class B: def __init__(): self.a = A() The file I actually execute: execute.py ...
Feephy's user avatar
  • 143
0 votes
3 answers
44 views

For class created from Python turtle module, instead of return functions at each method, how can data created from a method be used in different one?

For a class (snake class) created from the turtle module in Python: Problem 1. when the move() method is called, the snake segments are moving backwards instead of forward . The problem seems to be ...
chris's user avatar
  • 23
-1 votes
1 answer
83 views

How to add class variable values to a list, python 3x?

I'm trying to add class variable values to a list inside a function, but I'm not seeing any errors or the expected output? The comboxbox doesn't display when I uncomment the list code. Outside of the ...
James-Jesse Drinkard's user avatar
0 votes
0 answers
34 views

Unable to properly initialize a tkinter scrollbar inside a UI

I'm not an expert python programmer. After some time and effort I've built a tkinter UI that properly works. Recently, I've found myself needing to add a scrollbar inside the frame, since I need to ...
Elia Melloni's user avatar
0 votes
3 answers
46 views

How to run multiple instances of an object with two threads inside each object?

I'm trying to wrap two threaded functions inside an object and run a couple of instances of the object. So far I could only run the objects if I pull the threading outside the class. import threading ...
R.Orteza's user avatar
0 votes
2 answers
278 views

List all properties defined on a Pydantic BaseModel

Is there an elegant way to list all properties defined on a Pydantic BaseModel? It's possible to extract the list of fields via BaseModel.model_fields and the list of computed fields via BaseModel....
SultanOrazbayev's user avatar
1 vote
2 answers
70 views

On demand Python imports

I have the following situation: A module that contains a class Foo with some additional convenience functions for assembling Foo objects. A Foo object contains methods for interacting with data in an ...
Ash's user avatar
  • 205
0 votes
1 answer
114 views

Programatically create multiple instances of CustomTkinter Combobox Python

New to python and trying to create an app with customtkinter. The app lets users pick values from different drop-downs and generates codes based on the chosen value. Updated per comment from Mike-SMT: ...
Gautam's user avatar
  • 2,713
4 votes
3 answers
204 views

How to correctly define a classmethod that accesses a value of a mangled child attribute?

In Python, how do I correctly define a classmethod of a parent class that references an attribute of a child class? from enum import Enum class LabelledEnum(Enum): @classmethod def ...
SultanOrazbayev's user avatar

15 30 50 per page
1
2 3 4 5
34