akadjoker

Untitled

May 3rd, 2022
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. from tkinter import *
  2. from fpdf import FPDF
  3. import os
  4. import subprocess
  5. #INICIAR JANELA
  6. janela = Tk()
  7.  
  8.  
  9. def on_enter(event):
  10. butao_calc['background']='#006400'
  11. butao_calc['foreground']='#00FF00'
  12.  
  13. def on_leave(event):
  14. butao_calc['background']='#00FF00'
  15. butao_calc['foreground']='#006400'
  16. #DEFENIR TAMANHO DA JANELA
  17. WIDTH =janela.winfo_screenwidth()//2
  18. HEIGHT= janela.winfo_screenheight()-100
  19. winx = janela.winfo_screenwidth()//2- (WIDTH//2)
  20. winy = janela.winfo_screenheight()//2 -(HEIGHT//2)-50
  21. janela.geometry(f'{WIDTH}x{HEIGHT}+{winx}+{winy}')
  22. janela.resizable(False,False)
  23.  
  24. #VARIÁVEIS
  25. cor_letra = '#fff'
  26. tamanho=30
  27. botao = 15
  28. px,py=15,15
  29. comb =24
  30. salario , sub_alimentacao, valor_hora,num_hextra,opcao_hextra,num_filhos= StringVar(), StringVar(),StringVar(),StringVar(),StringVar(),StringVar()
  31. check1, check2 = IntVar(),IntVar(),
  32.  
  33. #DEFINIR TITULO DA JANELA
  34. janela.title('RECIBO VENCIMENTO')
  35.  
  36. #DEFINIR LOGO
  37.  
  38.  
  39. #DEFINIR FONTE
  40. fonte=('Arial',16,'bold')
  41. fonte2=('Arial',12,'bold')
  42. janela['bd']=10
  43. janela['bg']='#fff'
  44.  
  45. #BOTÃO CALCULAR
  46. butao_calc =Button(janela, text='Calcular', fg='#00FF00',bg ='#006400' ,width=botao,activeforeground='#00FF00',activebackground='#006400',bd=2)
  47. butao_calc.place(x=WIDTH//2-60,y=HEIGHT - 200)
  48.  
  49. #BOTÃO LIMPAR
  50. butao_limpar = Button(janela, text='Limpar', width=botao, bg='yellow',bd=2)
  51. butao_limpar.place(x=60,y=HEIGHT - 200)
  52.  
  53. #BOTÃO SAIR
  54. butao_sair = Button(janela, text='Sair', width=botao,bg='red',bd=2)
  55. butao_sair.place(x=WIDTH-180,y=HEIGHT - 200)
  56.  
  57. butao_calc.bind('<Enter>', on_enter)
  58. butao_calc.bind('<Leave>', on_leave)
  59.  
  60. #PDF
  61. #https://pyfpdf.readthedocs.io/en/latest/reference/cell/index.html
  62. pdf = FPDF('L', 'pt', 'A4')
  63. pdf.set_author("Joao")
  64. pdf.add_page()
  65.  
  66. def text(x1=0, y1=0, x2=0, y2=0, text='', font="arial", size=10,
  67. bold=False, italic=False, underline=False, align=""):
  68. if text:
  69. font = font.strip().lower()
  70. if font == 'arial black':
  71. font = 'arial'
  72. style = ""
  73. if bold: style += "B"
  74. if italic: style += "I"
  75. if underline: style += "U"
  76. align = {'I':'L','D':'R','C':'C','':'',None:None}[align]
  77. pdf.set_font(font,style,size)
  78. pdf.set_xy(x1,y1)
  79. pdf.cell(w=x2-x1,h=y2-y1,txt=text,border=0,ln=0,align=align)
  80.  
  81.  
  82. def line(x1=0, y1=0, x2=0, y2=0, size=0):
  83. pdf.set_line_width(size)
  84. pdf.line(x1, y1, x2, y2)
  85.  
  86. def rect(x1=0, y1=0, x2=0, y2=0, size=0):
  87. pdf.set_line_width(size)
  88. pdf.rect(x1, y1, x2, y2)
  89.  
  90. y = 20
  91. MAX = 820
  92.  
  93. rect(3,20,190,30)
  94. rect(3,70,190,30)
  95. rect(3,120,190,30)
  96.  
  97. rect(200,20,450,30)
  98. rect(200,70,450,30)
  99. rect(200,120,450,30)
  100.  
  101. text(10 ,40,180,30,"Nome do Funcionario")
  102. text(10 ,140,180,30,"Data")
  103. text(10 ,240,180,30,"Montante")
  104.  
  105. rect(370,520,400,30)
  106. line(600,640,800,640)
  107. text(550 ,960,180,30,"Assinatura")
  108.  
  109. #for i in range(100):
  110. # x =5 + i * 14
  111. # print(x)
  112. # text(x ,5,10,10,str(i))
  113.  
  114.  
  115.  
  116. pdf.output('save.pdf', 'F')
  117.  
  118.  
  119.  
  120. #LOOP DA JANELA
  121. janela.mainloop()
  122.  
  123.  
  124. #subprocess.Popen(['save.pdf'], shell=False)
Advertisement
Add Comment
Please, Sign In to add comment