Editor de texto em Tkinter
Publicado por Perfil removido (última atualização em 13/07/2011)
[ Hits: 17.631 ]
Esse é um pequeno editor de textos feito em Python. Utiliza a interface gráfica Tkinter.
#! /usr/bin/python
# -*- coding: UTF-8 -*-
from Tkinter import *
from tkFileDialog import asksaveasfilename,askopenfilename
#Começa a classe do editor:
class PyNotePad:
# Aqui fica a função inicial:
def __init__(self):
self.root = Tk()
self.root.wm_title("PyNotePad")# Aqui é o digito
# "inicia" a scroolbar
scrollbar = Scrollbar(self.root)
scrollbar.pack(side=RIGHT, fill=Y)
menubar = Menu(self.root)
#Aqui criamos os menus:
MENUarquivo = Menu(menubar)
MENUarquivo.add_command(label="Salvar", command=self.salvar)
MENUarquivo.add_command(label="Abrir", command=self.abrir)
menubar.add_cascade(label="Arquivo", menu=MENUarquivo)
MENUajuda = Menu(menubar)
MENUajuda.add_command(label="Sobre", command=self.sobre)
menubar.add_cascade(label="Ajuda", menu=MENUajuda)
self.root.config(menu=menubar)
# Aqui adicionamos a parte que fica o texto:
self.text = Text(self.root)
self.text.pack(expand=YES, fill=BOTH)
#aqui configura o scrollbar
self.text.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=self.text.yview)
# Por Fim, a janela:
self.root.mainloop()
def salvar(self): # Aqui é a função que salva o arquivo:
fileName = asksaveasfilename()
try:
file = open(fileName, 'w')
textoutput = self.text.get(0.0, END)
file.write(textoutput)
except:
pass
finally:
file.close()
def abrir(self):# Aqui é a função que abre um arquivo
fileName = askopenfilename()
try:
file = open(fileName, 'r')
contents = file.read()
self.text.delete(0.0, END)
self.text.insert(0.0, contents)
except:
pass
def sobre(self):# uma pequena função "sobre" :D
root = Tk()
root.wm_title("Sobre")
texto=("PyNotePad: Versão 1.0")
textONlabel = Label(root, text=texto)
textONlabel.pack()
# inicia o programa:
PyNotePad()
Script para obter um wallpaper de como está o globo em tempo real
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
[Resolvido] VirtualBox can't enable the AMD-V extension
Como verificar a saúde dos discos no Linux
Como instalar , particionar, formatar e montar um HD adicional no Linux?
Como automatizar sua instalação do Ubuntu para desenvolvimento de software.
Não consigo instalar distro antiga no virtualbox nem direto no hd (12)
Quais os códigos mais dificeis que vcs sabem fazer? (12)
systemd-resol... precisa ser reiniciado periodicamente [RESOLVIDO] (7)









