Python Online o'quv markazi ma'lumot guruhi
#notepad dasturi
import tkinter
import os
from tkinter import *
from tkinter.messagebox import *
from tkinter.filedialog import *
class Notepad:
__root = Tk()
__thisWidth = 300
__thisHeigt = 300
thisTextArea = Text(root)
thisMenuBar = Menu(root)
thisFileMenyu = Menu(thisMenuBar,tearoff=0)
thisEditMenyu = Menu(thisMenuBar,tearoff=0)
thisHelpMenyu = Menu(thisMenuBar,tearoff=0)
# To add scrolbar
thisScrollbar = Scrollbar(__thisTextArea)
__file = None
def init(self,**kwargs):
# Set icon
try:self.__root.wm_iconbitmap("Notepad.ico")
except:pass
# Set window size (the default is 300x300)
try:self.__thisWidth = kwargs['Width']
except KeyError:pass
try:self.__thisHeigt = kwargs['height']
except KeyError:pass
# Set the window text
self.__root.title("United - Notepad")
# Center the window
screenWidth = self.__root.winfo_screenwidth()
screenHeight = self.__root.winfo_screenheight()
# For left-aligin
left = (screenWidth / 2) - (self.__thisWidth / 2)
# For right-aligin
top = (screenHeight / 2) - (self.__thisHeigt / 2)
# For top and bottom
self.root.geometry('%dx%d+%d+%d' % (self.thisWidth,self.__thisHeigt,left,top))
# To make tho textarea auto resible
self.__root.grid_rowconfigure(0,weight=1)
self.__root.grid_columnconfigure(0,weight=1)
# Add controls (widget)
self.__thisTextArea.grid(sticky=N + E + S + W)
# To open new file
self.thisFileMenyu.add_command(label="New",command=self.newFile)
# To open alredy existing file
self.thisFileMenyu.add_command(label="Open", command=self.openFile)
# to save current file
self.thisFileMenyu.add_command(label="Save", command=self.saveFile)
# To create a line in the dialog
self.__thisFileMenyu.add_separator()
self.thisFileMenyu.add_command(label="Exit", command=self.quitApplication)
self.thisMenuBar.add_cascade(label="File",menu=self.thisFileMenyu)
# To give future of cut
self.thisEditMenyu.add_command(label='Cut',command=self.cut)
# To give future of copy
self.thisEditMenyu.add_command(label='Copy',command=self.copy)
# To give future of paste
self.thisEditMenyu.add_command(label='Paste',command=self.paste)
# To give future of editing
self.thisMenuBar.add_cascade(label='Edit',menu=self.thisEditMenyu)
# To create a future of description of the notepad
self.thisHelpMenyu.add_command(label="About_notepad",command=self.showAbout)
self.thisMenuBar.add_cascade(label='Help',menu=self.thisHelpMenyu)
self.root.config(menu=self.thisMenuBar)
self.thisScrollbar.pack(side=RIGHT,fill=Y) # error
# scrollBar will adjust automatically according to the content
self.thisScrollbar.config(command=self.__thisTextArea.yview)
self.__thisTextArea.config(yscrollcommand=self.thisScrollbar.set)
def __quitApplication(self):
self.__root.destroy()
# exit()
def __showAbout(self):
showinfo('Notepad',"Bahodir Obloqulov")
def __openFile(self):
self.__file = askopenfilename(defaultextension=".txt",filetypes=[("All Files","*.*"),("Text documents", "*.txt")])
if self.__file == "":
# no file to open
self.__file = None
else:
# Try to open the file
# set the window title
self.root.title(os.path.basename(self.file)+"-Notepad")
self.__thisTextArea.delete(1.8,END)
file = open(self.__file,"r")