- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 120字
- 2021-08-27 19:44:00
How to do it...
This example shows how to create a login form with two entry instances for the username and password fields. Each character of password is displayed as an asterisk to avoid showing it in clear text:
import tkinter as tk class LoginApp(tk.Tk): def __init__(self): super().__init__() self.username = tk.Entry(self) self.password = tk.Entry(self, show="*") self.login_btn = tk.Button(self, text="Log in", command=self.print_login) self.clear_btn = tk.Button(self, text="Clear", command=self.clear_form) self.username.pack() self.password.pack() self.login_btn.pack(fill=tk.BOTH) self.clear_btn.pack(fill=tk.BOTH) def print_login(self): print("Username: {}".format(self.username.get())) print("Password: {}".format(self.password.get())) def clear_form(self): self.username.delete(0, tk.END) self.password.delete(0, tk.END) self.username.focus_set() if __name__ == "__main__": app = LoginApp() app.mainloop()
The Log in button prints the values in the console, whereas the Clear button removes the content of both entries and returns the focus to the entry for username:

推薦閱讀
- 微服務設計(第2版)
- JavaScript:Functional Programming for JavaScript Developers
- Go語言高效編程:原理、可觀測性與優化
- Mastering Python High Performance
- YARN Essentials
- OpenShift在企業中的實踐:PaaS DevOps微服務(第2版)
- 你不知道的JavaScript(中卷)
- Spring+Spring MVC+MyBatis整合開發實戰
- SQL Server與JSP動態網站開發
- Learning Probabilistic Graphical Models in R
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- 西門子S7-200 SMART PLC編程從入門到實踐
- C語言從入門到精通
- Oracle GoldenGate 12c Implementer's Guide
- Creating Data Stories with Tableau Public