I wrote a small pygame app that fills random colors on the device's screen:
import sys, os
andr = None # is running on android
try:
import android
andr = True
except ImportError:
andr = False
try:
import pygame
import sys
import random
import time
from pygame.locals import *
pygame.init()
fps = 1 / 3 # 3 fps
width, height = 640, 480
screen = pygame.display.set_mode((width, height), FULLSCREEN if andr else 0) # fullscreen is required on android
width, height = pygame.display.get_surface().get_size() # on android resolution is auto changing to screen resolution
while True:
screen.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.flip()
time.sleep(fps)
except Exception as e:
open('error.txt', 'w').write(str(e)) # Save error into file (for android)
But there are no UI elements (like in kivy) (but I can draw them), so I want to show/hide the keyboard from code. But I can't find docs about android.show_keyboard and android.hide_keyboard
My attempts:
- When I call
android.show_keyboard()
, I get an error saying that 2 args are required - When I add random args:
android.show_keyboard(True, True)
, I also get an error saying that varinput_type_
is not global - When I change the 2nd arg to a string:
android.show_keyboard(True, 'text')
, the app just crashes without saving the error to file.
Can someone help me with how I can show/hide the keyboard?