Apr-03-2021, 10:11 AM
Hello,
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
sorry for my bad english
thanks in advance
Gregor
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] else: 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): pygame.event.pump() 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 SCREEN.fill(farben.blue) # Disconnected if connected == 'disconnected': # statischer disconnected Button button_modul.disconnected_button.draw_button(SCREEN) # 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 button_modul.connected_button.draw_button(SCREEN) # 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: button_modul.text_box.process_event(event) button_modul.text_box.draw_button(SCREEN) # --- Update --- # Zählvariable round += 1 if round== 1000: round = 0 else: pass # Refresh pygame.display.update() if __name__ == '__main__': 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
Gregor