quinta-feira, 12 de janeiro de 2023

Gerar TXT nome com data

from datetime import datetime

        self.txts=[]

        self.file_name = 'fishfromKML{}.txt'.format(datetime.now().strftime("%Y%m%d%H%M%S%z"))

        self.txts.append(self.nomes)

        with open (self.file_name, 'w') as self.f:

            self.f.write(str(self.txts)) 

self.nomes = ['casa']

Abrir arquivo (Open File)

 

Import CSV

from tkinter import *

import pandas as pd

with open('Filename.csv',newline='') as self.myfile:

            self.csv_file = csv.reader(self.myfile, delimiter=',')

 

            self.Menusyn=[]

            for i in self.csv_file:

                self.Menusyn.append(i[0])

            self.syn = list()

            for self.value in self.Menusyn:

                if self.value not in self.syn:

                    self.syn.append(self.value)

        def textnome(event):

            self.doctext = pd.read_csv("Filename.csv",encoding='utf-8')

            self.readertx = pd.DataFrame(self.doctext)

            self.nomeerrado= self.doctext.columns[0]

            self.doc_selecao = self.readertx.loc[self.readertx[self.nomeerrado] == self.Combosyn.get()]

            self.linhatx = 0

            self.frame = 4

            while self.linhatx < len(self.doc_selecao):

                       self.locali = self.doc_selecao.iloc[self.linhatx,1]

                       tk.Label(self.brachs, text = self.locali).grid(row=self.frame,column=2)

                       tk.Label(self.brachs, text = "Current name").grid(row=3,column=2)

                       self.linhatx = self.linhatx+1

                       self.frame = self.frame+1

        self.brachs = root

        self.frame = tk.Frame(self.brachs)

        self.brachs = Tk()

        self.brachs.geometry("500x100")

        tk.Label(self.brachs, text = "Nome").grid(row=1,column=1)

        self.brachs.title("Find name")

        self.Combosyn = ttk.Combobox(self.brachs, width = 30, height = 20)

        self.Combosyn.grid(row=2, column=1)

        self.syn=sorted(self.syn)

        self.Combosyn ['values']= self.syn

        self.Combosyn.bind("<<ComboboxSelected>>",textnome)

Adicionar imagem no Frame

 

pip install pillow

from PIL import ImageTk, Image       

        widget1 = Frame(master)

        #rootFrame.Destroy()

        widget1.grid()

        imagem = ImageTk.PhotoImage(Image.open("namephoto.png"))

        image = Image.open("namephoto.png")

        photo = ImageTk.PhotoImage(image)

        imagem = Label(master, text = "infomation", image = photo)

        imagem.image = photo

        imagem.grid()

        teste = Label(widget1)

        teste.grid()       

terça-feira, 10 de janeiro de 2023

Setup - gerar exe

from cx_Freeze import setup, Executable


import os, sys

import cx_Freeze

base='win32GUI'

#if sys.platform =="win32":

#    base = 'win32GUI'

#sys.setrecursionlimit(100000)

sys.argv.append("build")

#python runexecx.py bdist_msi # ou # python runexecx.py build# no cmd digitar 

build_exe_opitions= {'packages':['tkinter', 'datetime', 'geopandas', 'pandas', 'csv', 'os', 'sys', 'PIL', 'webbrowser', 'html'],'include_files':['Chave_sinonimia.csv','mapa1.HTML','Peixe.png','ibicui.json'], 'excludes':['matplotlib','numpy', 'abc', ' argparse', 'asyncio', 'atexit', 'base64', 'bdb', 'binascii', 'bisect', 'bz2', 'calendar', 'cmd', 'codecs', 'codeop', '__future__', 'collections', 'collections.abc', 'concurrent', 'contexlib', 'copy', 'copyreg', 'ctypes', 'dataclasses', 'decimal', 'difflib', 'dis', 'distutils', 'doctest', 'email', 'enum', 'errno', 'fnmatch', 'fractions', 'functools', 'gc', 'genericpach', 'getopt', 'gettext', 'glob', 'heapq', 'hashlib', 'http', 'importlib', 'inspect', 'io', 'intertools', 'keyword', 'lib2to3', 'linecache', 'locale', 'logging','marshal', 'math', 'msvcrt', 'multiprocessing', 'nt', 'ntpach', 'numbers', 'opcode', 'operator', 'os.pach', 'pach', 'patchlib', 'pdb', 'pkgutil', 'platform', 'plistlib', 'posixpath', 'pprint', 'pydoc', 'pydoc_data', 'quopri', 'random', 're', 'reprlib', 'runpy', 'select', 'selectors', 'shlex', 'shutil', 'signal', 'soket', 'sre_copile','sre_constants', 'sre_parse', 'stats', 'statistics', 'string', 'stringprep', 'struct', 'subprocess', 'sysconfig', 'tarfile', 'tempfile', 'test', 'textwrap', 'threading', 'time', 'token', 'tokenize', 'traceback', 'tracemalloc', 'tty', 'types', 'tuping', 'unicodedata', 'unittest', 'urllib', 'warnings', 'weakref', 'winreg', 'xml', 'xmlrpc', 'zipfile', 'zipimport', 'zlib' ]}

cx_Freeze.setup(name='teste', executables=[Executable('pograma_instalpy.py', base = base)],)

def find_data(filename):#15:48

    if getattr(sys, 'frozen', False):

        datadir=os.patch.dirname(sys.executable)

    else:

        datadir = os.path.dirname(__file__)

    return os.patch.join(datadir,filename)