arcade.gui.experimental.password_input 源代码
from __future__ import annotations
from typing import Optional
from arcade.gui import UIInputText, UIEvent, UITextEvent, Surface
[文档]
class UIPasswordInput(UIInputText):
"""A password input field. The text is hidden with asterisks."""
[文档]
def on_event(self, event: UIEvent) -> Optional[bool]:
if isinstance(event, UITextEvent):
event.text = event.text.replace("\n", "") # remove new lines!
event.text = event.text.replace("\r", "") # remove new lines!
return super().on_event(event)
[文档]
def do_render(self, surface: Surface):
self.layout.begin_update()
position = self.caret.position
text = self.text
self.text = "*" * len(self.text)
super().do_render(surface)
self.text = text
self.caret.position = position
self.layout.end_update()