mirror of
https://github.com/Apress/foundations-of-pygtk-development.git
synced 2026-01-04 23:20:06 +01:00
Initial commit
This commit is contained in:
43
Basic_Widgets/GtkEntry.py
Normal file
43
Basic_Widgets/GtkEntry.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
import os
|
||||
|
||||
class AppWindow(Gtk.ApplicationWindow):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.set_border_width(10)
|
||||
prompt_str = "What is the password for " + os.getlogin() + "?"
|
||||
question = Gtk.Label(prompt_str)
|
||||
label = Gtk.Label("Password:")
|
||||
passwd = Gtk.Entry()
|
||||
passwd.set_visibility(False)
|
||||
passwd.set_invisible_char("*")
|
||||
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
|
||||
hbox.pack_start(label, False, False, 5)
|
||||
hbox.pack_start(passwd, False, False, 5)
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
|
||||
vbox.pack_start(question, False, False, 0)
|
||||
vbox.pack_start(hbox, False, False, 0)
|
||||
self.add(vbox)
|
||||
|
||||
class Application(Gtk.Application):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, application_id="org.example.myapp",
|
||||
**kwargs)
|
||||
self.window = None
|
||||
|
||||
def do_activate(self):
|
||||
if not self.window:
|
||||
self.window = AppWindow(application=self, title="Password")
|
||||
self.window.show_all()
|
||||
self.window.present()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Application()
|
||||
app.run(sys.argv)
|
||||
Reference in New Issue
Block a user