Pycharm – die besten Beiträge

Customtkinter "master" Parameter beim erstellen von einem Textfeld?

Hey,

ich habe eine Klasse erstellt die ein Hauptfenster erstellt und möchte aus einer anderen klasse einen Textfeld erstellen der sich auf das Hauptfenster bezieht.
So wie ich es verstanden habe braucht man dafür den Parameter "master" um vorzugeben in welchem Fenster nun der Textfeld angezeigt werden soll.
Leider funktioniert das bei mir nicht so richtig. Hat jemand davon Ahnung und kann mir meinen Fehler zeigen?
lieben Dank! :)

main.py

import view
import controller
import customtkinter as ctk

class Main(view.MainWindow):
   def __init__(self):
       super().__init__()
       self.main_window = view.MainWindow()
       self.main_window.set_size("1680", "900")
       self.main_window.set_title("YourTerminal")
       controller.InputBoxMain()# Nach meinem Verständnis muss hier der Master-Parameter angegeben werden. Wie übergebe ich diesen?

   def run(self):
       self.main_window.get_window().mainloop()

if __name__ == "__main__":
    app = Main()
    app.run()

view.py

import customtkinter as ctk


class MainWindow:
   def __init__(self):
       self.window = ctk.CTk()

   def set_size(self, width, height):
       self.window.geometry(f"{width}x{height}")

   def set_title(self, title):
       self.window.title(title)

   def get_window(self):
       return self.window

class WindowTemplate:
   def __init__(self):
       self.window = ctk.CTkToplevel()

   def set_size(self, width, height):
       self.window.geometry(f"{width}x{height}")

   def set_title(self, title):
       self.window.title(title)

   def get_window(self):
       return self.window

# der master Parameter gibt an wo diese Box angezeigt werden soll
class InputBoxTemplate:
    def __init__(self, master):  # Wie übergebe ich den master Parameter?
        self.master = master
        self.box = ctk.CTkEntry(self.master)

    def set_size(self, width, height, y, x):
        self.box.place(width=width, height=height, pady=y, padyx=x)

    def set_placeholder(self, placeholder):
        self.box._placeholder_text(f"{placeholder}")

controller.py

import view
import customtkinter as ctk
import main
class InputBoxMain(view.InputBoxTemplate, main.Main):
    def __init__(self):
        super().__init__()
        self.master = ctk.CTk()
        self.window = view.InputBoxTemplate(self.master)# Oder der Master-Parameter wird hier übergeben? Hier versuche ich master auf ctk.CTk zu beziehen. Das ist das Haupfenster.
        self.window.set_size(200, 200, 10, 10)
        self.window.set_placeholder("Hier steht der Placeholder")

Hier die Fehlermeldung falls relevant:

Traceback (most recent call last):

 File , line 1, in <module>

  import view

 File , line 2, in <module>

  import main

 File , line 2, in <module>

  import controller

 File " line 4, in <module>

  class InputBoxMain(view.InputBoxTemplate, main.Main):

            ^^^^^^^^^^^^^^^^^^^^^

AttributeError: partially initialized module 'view' has no attribute 'InputBoxTemplate' (most likely due to a circular import)

Code, Programmiersprache, Python, Python 3, Objektorientierte Programmierung, Tkinter, Pycharm

pygame auf der stelle laufen?

Hallo,

ich muss für die schule ein pygame spiel erstellen und kenn mich leider nicht wirklich damit aus..

ich möchte dass mein character die ganze zeit auf einer stelle steht aber dabei 'läuft', habe dafür auch dier passenden bilder, weiss aber leider nicht wie ich das im code angebe..

bis jetzt habe ich halt nur ein hintergrund und mein character und der gegner sind darauf..

würd mich echt über hilfe freuen.

hier ist mein code:

import pygame

# pygame setup
pygame.init()
screen = pygame.display.set_mode((1104, 621))
clock = pygame.time.Clock()
running = True

Hintergrund = pygame.image.load('hintergrund/back.png')
screen.blit(Hintergrund, (0, 0))
charwalk1 = pygame.image.load('characters/girl-2A.png')
screen.blit(charwalk1, (200, 300))
monster = pygame.image.load('monster/DAGRONS5.png')
screen.blit(monster, (600, 210))




pygame.display.set_caption('fighter')

charwalk1 = pygame.image.load('characters/girl-2A.png')
charwalk2 = pygame.image.load('characters/girl-2B.png')
charwalk3 = pygame.image.load('characters/girl-2C.png')
charwalk4 = pygame.image.load('characters/girl-2D.png')
charwalk5 = pygame.image.load('characters/girl-2E.png')

monster = pygame.image.load('monster/DAGRONS5.png')



while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.image.load('hintergrund/back.png')
        pygame.display.flip()



class Player(pygame.sprite.Sprite):
    def __init__(self):
        self.player_walk = (charwalk1, charwalk2, charwalk3, charwalk4, charwalk5)
Spiele, PC, Computer, App, Code, Programmiersprache, Python, Pygame, Pycharm

wie behebe ich diesen fehler?

Hallo!

Kann mir jemand helfen diese Fehler zu beheben?

FEHLER 1 :Traceback (most recent call last):

 File "C:\Users\arrou\OneDrive\Desktop\cheese\für acc\tmmail\main.py", line 37, in <module>

class mailtm_gui(ctk.CTk):

Fehler 2 :  File "C:\Users\arrou\OneDrive\Desktop\cheese\für acc\tmmail\main.py", line 59, in mailtm_gui

  knopf = ctk.CTkButton(main, text="n", command=neum())

FEHLER 3 :  File "C:\Users\arrou\OneDrive\Desktop\cheese\für acc\tmmail\main.py", line 56, in neum

  mail_body = ctk.CTkEntry(mail_window, placeholder_text='Subject: ' + message['subject'] + '\nBody: ' + (message['text'] if message['text'] else message['html']), width=900, font=('Helvetica', 20))

TypeError: 'module' object is not subscriptable

import customtkinter as ctk
from mailtm import *
from mailtm import message


def listener(message):
    print("\nSubject: " + message['subject'] + str(listener))
    print("Content: " + message['text'] if message['text'] else message['html'] + str(listener))


test = Email()
print("\nDomain: " + test.domain)

test.register()
print("\nEmail Adress: " + str(test.address))


test.start(listener, interval=3)
print("\nHab Sabr.....")


main = ctk.CTk()
main.geometry("500x320")
main.title("Temp mail By Amjn")


emaila = ctk.CTkEntry(main, placeholder_text="         " + test.address, width=900, font=("Helvetica", 20))
emaila.configure(state="readonly")
emaila._corner_radius = 10
emaila.pack()


Copyt = ctk.CTkLabel(main, text="Copy Email", font=("Helvetica", 20))
Copyt.pack()


class mailtm_gui(ctk.CTk):
    def __init__(self):
        ctk.CTk.__init__(self)
        self.geometry('500x320')
        self.title('Temp mail By Amjn')
        listener = Email()
        listener.register()
        emaila = ctk.CTkEntry(self, placeholder_text=listener.address, width=900, font=('Helvetica', 20))
        emaila.configure(state='readonly')
        emaila._corner_radius = 10
        emaila.pack()
        listener.start(listener, interval=3)

    def neum():
        mail_window = ctk.CTkToplevel()
        mail_window.title("amjs tm by mailtm")
        mail_window.geometry('500x320')
        mail_window.corner_radius = 30
        mail_window.resizable(width=True, height=True)
        mail_body = ctk.CTkEntry(mail_window, placeholder_text='Subject: ' + message['subject'] + '\nBody: ' + (message['text'] if message['text'] else message['html']), width=900, font=('Helvetica', 20))
        mail_body.pack()

    knopf = ctk.CTkButton(main, text="n", command=neum())


main.mainloop()
Code, Programmiersprache, Python, Python 3, Tkinter, Pycharm

TypeError: can only concatenate str (not "function") to str?

ich möchte eine ui für mailtm erstellen aber bekomme kein output raus also wenn email ankommen werden sie nicht angezeigt und wenn ich listener eingebe bekomme ich jedes mal den gleichen fehler code

Fehler code:

TypeError: can only concatenate str (not "function") to str

from mailtm import *


def listener(message):
    print("\nSubject: " + message['subject'] + str(listener))
    print("Content: " + message['text'] if message['text'] else message['html'] + str(listener))


test = Email()
print("\nDomain: " + test.domain)

test.register()
print("\nEmail Adress: " + str(test.address))


test.start(listener, interval=3)
print("\nHab Sabr.....")


main = ctk.CTk()
main.geometry("500x320")
main.title("Temp mail By Amjn")


emaila = ctk.CTkEntry(main, placeholder_text="         " + test.address, width=900, font=("Helvetica", 20))
emaila.configure(state="readonly")
emaila._corner_radius = 10
emaila.pack()


Copyt = ctk.CTkLabel(main, text="Copy Email", font=("Helvetica", 20))
Copyt.pack()


def neuw(self=None):
    neu = ctk.CTkToplevel(main)
    neu.title("Emails              (MADE BY AMJN)")
    neu.geometry("500x320")
    neu.corner_radius = 30
    neu.resizable(width=True, height=True)

    Ausg = ctk.CTkEntry(neuw, placeholder_text=("         ") + listener, width=900, font=("Helvetica", 20))
    Ausg.pack()


knopf = ctk.CTkButton(main, text="Emails", font=("Helvetica", 20), command=neuw)
knopf.pack(pady=20)

main.mainloop()
Code, Programmiersprache, Python, UI, Python 3, Tkinter, Pycharm

SSL-Paket kann nicht installiert werden. Kann mir jemand das Problem erklären?


Servus alle zusammen.

Ich habe mal wieder eins der unnötigsten Probleme die man so gar nicht gebrauchen kann.
Vorab: Ich verwende PyCharm CommunityEdit2023

Folgende Problematik stellt sich mir:Ich versuche über den PyCharm Interpreter das Paket ssl zu laden und erhalte:

Collecting ssl

 Using cached ssl-1.16.tar.gz (33 kB)

 Using cached ssl-1.15.tar.gz (32 kB)




  ERROR: Command errored out with exit status 1:

   command: 'D:\Python\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Paddy\\AppData\\Local\\Temp\\pip-install-6xunn48y\\ssl_93be5a3dfd464eefb55e12eacc1c7aae\\setup.py'"'"'; __file__='"'"'C:\\Users\\Paddy\\AppData\\Local\\Temp\\pip-install-6xunn48y\\ssl_93be5a3dfd464eefb55e12eacc1c7aae\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Paddy\AppData\Local\Temp\pip-pip-egg-info-xz6xi0b2'

     cwd: C:\Users\Paddy\AppData\Local\Temp\pip-install-6xunn48y\ssl_93be5a3dfd464eefb55e12eacc1c7aae\

  Complete output (6 lines):

  Traceback (most recent call last):

   File "<string>", line 1, in <module>

   File "C:\Users\Paddy\AppData\Local\Temp\pip-install-6xunn48y\ssl_93be5a3dfd464eefb55e12eacc1c7aae\setup.py", line 33

    print 'looking for', f

       ^

  SyntaxError: Missing parentheses in call to 'print'. Did you mean print('looking for', f)?

  ----------------------------------------

WARNING: Discarding https://files.pythonhosted.org/packages/83/21/f469c9923235f8c36d5fd5334ed11e2681abad7e0032c5aba964dcaf9bbb/ssl-1.16.tar.gz#sha256=ac21156fee6aee9eb8d765bbb16f5f49492d81ff4b22f7b8fc001d2251120930 (from https://pypi.org/simple/ssl/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

  ERROR: Command errored out with exit status 1:

   command: 'D:\Python\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Paddy\\AppData\\Local\\Temp\\pip-install-6xunn48y\\ssl_0d4afefa00504f218b834c3475a8235c\\setup.py'"'"'; __file__='"'"'C:\\Users\\Paddy\\AppData\\Local\\Temp\\pip-install-6xunn48y\\ssl_0d4afefa00504f218b834c3475a8235c\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Paddy\AppData\Local\Temp\pip-pip-egg-info-2f8p2rk1'

     cwd: C:\Users\Paddy\AppData\Local\Temp\pip-install-6xunn48y\ssl_0d4afefa00504f218b834c3475a8235c\

  Complete output (6 lines):

  Traceback (most recent call last):

   File "<string>", line 1, in <module>

   File "C:\Users\Paddy\AppData\Local\Temp\pip-install-6xunn48y\ssl_0d4afefa00504f218b834c3475a8235c\setup.py", line 74

    print 'looking for', f

       ^

  SyntaxError: Missing parentheses in call to 'print'. Did you mean print('looking for', f)?

  ----------------------------------------

WARNING: Discarding https://files.pythonhosted.org/packages/3a/c2/846a19d1572ec6cb8ac438d58a898de8926d32e13f0355cdf4ab00864b5f/ssl-1.15.tar.gz#sha256=1266302ce62c4b60c7ca0e1d3d104ba11d2749e5881d8ac4f006cf9a0446d589 (from https://pypi.org/simple/ssl/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

ERROR: Could not find a version that satisfies the requirement ssl (from versions: 1.15, 1.16)

ERROR: No matching distribution found for ssl

WARNING: You are using pip version 21.1.3; however, version 24.0 is available.

You should consider upgrading via the 'D:\Python\python.exe -m pip install --upgrade pip' command.

Via cmd erhalte ich die gleiche Meldung.
Ich habe alle Python-Versionen schon deinstalliert, System neu gestartet und wieder installiert. Das gleiche habe ich auch mit pip probiert.

Kann mir hier vielleicht jemand weiterhelfen?

Vielen Dank und liebe Grüße im Voraus! :)

cmd, Code, Error, Python, SSL, pip, Python 3, Windows 10, Pycharm

Python Fehlermeldung "KeyError: 'data'"?

Ich möchte gerne einen KI Discord Server machen. Die KI hab ich schon und diese hat auch eine API(?). Ich hab den Bot auch schon auf dem Server und ich kann auch Prompts eingeben. Aber wenn ich Prompt eingebe, kommt bei diesem Code:

import discord
from gradio_client import Client


TOKEN = 'MeinToken'
FOOOCUS_API_URL = 'http://127.0.0.1:7865/'


fooocus_client = Client(FOOOCUS_API_URL)


intents = discord.Intents.default()
client = discord.Client(intents=intents)


@client.event
async def on_ready():
    print(f'{client.user} ist eingeloggt!')


@client.event
async def on_message(message):
    if message.channel.name == 'prompt-kanal' and message.author != client.user:
        result = fooocus_client.predict(message.content, fn_index=2)
        await message.channel.send(file=discord.File(result))


client.run(TOKEN)

Diese Fehlermeldung:

2024-04-16 15:35:07 ERROR discord.client Ignoring exception in on_message
Traceback (most recent call last):
File "C:...\venv\Lib\site-packages\gradio_client\compatibility.py", line 105, in _predict
output = result["data"]
~~~~~~^^^^^^^^
KeyError: 'data'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:...\venv\Lib\site-packages\discord\client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "c:...\bot.py", line 19, in on_message
result = fooocus_client.predict(message.content, fn_index=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:...\venv\Lib\site-packages\gradio_client\client.py", line 459, in predict
).result()
^^^^^^^^
File "C:...\venv\Lib\site-packages\gradio_client\client.py", line 1374, in result
return super().result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users..._base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Users..._base.py", line 401, in __get_result
raise self._exception
File "C:\Users...\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:...\compatibility.py", line 65, in _inner
predictions = _predict(*data)
^^^^^^^^^^^^^^^
File "C:...\compatibility.py", line 119, in _predict
raise KeyError(
KeyError: 'Could not find 'data' key in response. Response received: {'detail': [{'type': 'model_attributes_type', 'loc': ['body'], 'msg': 'Input should be a valid dictionary or object to extract fields from', 'input': '{"data": [""], "fn_index": 2, "session_hash": "d7f62bf0-174c-45fe-b3f6-c5e7f00848d3"}', 'url': 'https://errors.pydantic.dev/2.1/v/model_attributes_type'}]}'

Ich checke einfach nicht, woran das liegen könnte...

Linux, Bot, cmd, Code, künstliche Intelligenz, Programmiersprache, Python, Python 3, Pycharm, Discord, Discord Bot, ChatGPT

Meistgelesene Beiträge zum Thema Pycharm