This repository has been archived on 2020-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
py-gva/gui-tkinter.py

102 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
ZetCode Tkinter tutorial
In this example, we use the pack
manager to create a review example.
Author: Jan Bodnar
Website: www.zetcode.com
"""
from tkinter import Tk, Text, TOP, BOTH, X, N, LEFT
from tkinter.ttk import Frame, Label, Entry, Button
from libs.paylib import Transaction
import sys, threading
class StdoutRedirector(object):
def __init__(self, text_widget):
self.text_widget = text_widget
def write(self, s):
self.text_widget.insert('end', s)
self.text_widget.see('end')
def flush(self):
pass
class Pay(Frame):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.master.title("Paiement Ḡ1")
self.pack(fill=X)
frame1 = Frame(self)
frame1.pack(fill=X)
recipientLabel = Label(frame1, text="Destinataire:", width=12)
recipientLabel.pack(side=LEFT, padx=5, pady=5)
self.recipientEntry = Entry(frame1)
self.recipientEntry.pack(fill=X, padx=5, expand=True)
frame2 = Frame(self)
frame2.pack(fill=X)
AmountLabel = Label(frame2, text="Montant:", width=12)
AmountLabel.pack(side=LEFT, padx=5, pady=5)
self.AmountEntry = Entry(frame2, width=7)
self.AmountEntry.pack(side=LEFT, padx=5)
frame3 = Frame(self)
frame3.pack(fill=X)
commentLabel = Label(frame3, text="Commentaire:", width=12)
commentLabel.pack(side=LEFT, padx=5, pady=5)
self.commentEntry = Entry(frame3)
self.commentEntry.pack(fill=X, padx=5, expand=True)
frame4 = Frame(self)
frame4.pack()
self.sendButton = Button(frame4, text="Envoyer", command=self.ProceedPaiement)
self.sendButton.pack(side=LEFT, padx=5, pady=5, expand=True)
frame5 = Frame(self, width=200, height=300)
frame5.pack()
self.textbox = Text(frame5, wrap='word')
self.textbox.pack()
sys.stdout = StdoutRedirector(self.textbox)
def ProceedPaiement(self):
try:
recipient = str(self.recipientEntry.get())
amount = int(self.AmountEntry.get())
except:
print("Please enter the recipient's public and the amount\n")
else:
comment = str(self.commentEntry.get())
print("Paiement en cours ... " + recipient)
trans = Transaction(recipient, amount, comment)
trans.send()
recipient = amount = comment = None
def main():
def starter():
root = Tk()
root.geometry("500x300+300+300")
app = Pay()
root.mainloop()
thread = threading.Thread(target=starter)
thread.start()
if __name__ == '__main__':
main()