Python Forum
Textbox is being overdrawn
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Textbox is being overdrawn

I am coding a program to controll a Tello EDU.
Right now I try to implement a take-a-photo button. It works, but after taking the photo, I want the user to be able to name the picture. For this I want to pop up a little Textbox on the screen after taking the photo.

Class TextBox i coded as shown below.
Actually i named variables etc. in German, I changed all of the names into English for this post for a better understanding. I hope I didnt forget anything

class TextBox():
    def __init__(self, x, y, width, height, buttoncolor, text_input, textcolor, fontsize):
        self.x = x
        self.y = y
        self.width= width
        self.height= height
        self.buttoncolor= buttoncolor
        self.text_input = text_input
        self.textcolor= textcolor
        self.fontsize= fontsize

    def process_event(self, event):
        if event.type == pygame.KEYDOWN:
            if controlling.is_key_pressed("BACKSPACE"):
                self.text_input = self.text_input[:-1]
                self.text_input += event.unicode

    def draw_button(self, SCREEN):
        rect_button= Rect(self.x, self.y, self.width, self.height)
        pygame.draw.rect(SCREEN, self.buttoncolor, rect_button)
        text_as_button= self.fontsize.render(self.text_input, True, self.textcolor)
        SCREEN.blit(text_as_button, (self.x, self.y))
in the controlling module i have the function:
def is_key_pressed(key):
    return bool(pygame.key.get_pressed()[getattr(pygame, "K_" + key)])
my main function looks like this
def main():
    # --- Initialisierung ---
    connected = 'disconnected'
    steuerung_aktiv = False

    initialisieren_return = pygame_funktions.initialisieren()
    SCREEN = initialisieren_return['SCREEN']

    # controlling initialisierung

    controlling_return = {'pushtimes': [0], 'seccounter': 0}


    # Objekterstellung

    drone = tello.Tello()

    # Loop init
    run = True
    round = 0

    # Schleife
    while run:
        # --- Fensteraufbau ---
        # background


        # Disconnected
        if connected == 'disconnected':

            # statischer disconnected Button

            # interaktiver 'verbinden' button
            button_modul.direktverbinden_button.draw_button(SCREEN, button_modul.direktverbinden_button.geklickt, button_modul.direktverbinden_button.action)

            # Wenn 'Verbinden' Button geklickt wird
            if button_modul.direktverbinden_button.action == True:
                connected = 'connected'
                button_modul.direktverbinden_button.action = False


        # connected
        elif connected == 'connected':

            # connected-button zeichnen

            # check connection every 1000 rounds:

            if round == 0:
                connected = dronen_functions.check_connection(drone)

        # Fensterevents
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                run = False
            if steuerung_aktiv == False:

        # --- Update ---

        # Zählvariable
        round += 1
        if round== 1000:
            round = 0

        # Refresh


if __name__ == '__main__':
actually the textbox works, i can type in a text and it gets drawn in the text_box objekt BUT! i can only see it for a minimal part of a second if i change anything in the screen. like maybe moving my mouse or typing text. if i leave the screen with no action, the text_box object dissappears. what am i doing wrong?

sorry for my bad english
thanks in advance
Here my example.
Here is my example

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Pygame] Problems with my textbox SheeppOSU 1 1,182 May-27-2019, 12:03 AM
Last Post: metulburr
  [PyGame] Returning information from textbox? mzmingle 5 1,245 Nov-03-2018, 09:34 PM
Last Post: mzmingle

Forum Jump:

User Panel Messages

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