Python tkinter text editor
În Tkinter, Text Editor este widget-ul folosit pentru a obține intrările utilizatorilor sau pentru ca utilizatorii să-și scrie răspunsul ca text. Unele aplicații ale editorilor de text sunt: blocnotes, bloc de cuvinte etc. Tkinter are, de asemenea, widget pentru editor de text pe care îl putem folosi în aplicația noastră pentru a îmbunătăți sau extinde funcționalitatea acesteia.
Fereastră simplă în tkinter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# FILE: main01.py
# RUN : python3 main01.py
# -------------------------------------------BEGIN file
import tkinter as tk
class App(tk.Tk):
def __init_(self):
super().__init__()
if __name__ == "__main__":
app = App()
app.mainloop()
# ---------------------------------------------END file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #!/usr/bin/python3 # -*- coding: utf-8 -*- # FILE: main01.py # RUN : python3 main01.py # -------------------------------------------BEGIN file import tkinter as tk class App(tk.Tk): def __init_(self): super().__init__() if __name__ == "__main__": app = App() app.mainloop() # ---------------------------------------------END file |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from tkinter import *
from tkinter import messagebox
class MenuBar(Menu):
def __init__(self, ws):
Menu.__init__(self, ws)
file = Menu(self, tearoff=False)
file.add_command(label="New")
file.add_command(label="Open")
file.add_command(label="Save")
file.add_command(label="Save as")
file.add_separator()
file.add_command(label="Exit", underline=1, command=self.quit)
self.add_cascade(label="File",underline=0, menu=file)
edit = Menu(self, tearoff=0)
edit.add_command(label="Undo")
edit.add_separator()
edit.add_command(label="Cut")
edit.add_command(label="Copy")
edit.add_command(label="Paste")
self.add_cascade(label="Edit", menu=edit)
help = Menu(self, tearoff=0)
help.add_command(label="About", command=self.about)
self.add_cascade(label="Help", menu=help)
def exit(self):
self.exit
def about(self):
messagebox.showinfo('PythonGuides', 'Python Guides aims at providing best practical tutorials')
class MenuDemo(Tk):
def __init__(self):
Tk.__init__(self)
menubar = MenuBar(self)
self.config(menu=menubar)
if __name__ == "__main__":
ws=MenuDemo()
ws.title('Python Guides')
ws.geometry('300x200')
ws.mainloop()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | from tkinter import * from tkinter import messagebox class MenuBar(Menu): def __init__(self, ws): Menu.__init__(self, ws) file = Menu(self, tearoff=False) file.add_command(label="New") file.add_command(label="Open") file.add_command(label="Save") file.add_command(label="Save as") file.add_separator() file.add_command(label="Exit", underline=1, command=self.quit) self.add_cascade(label="File",underline=0, menu=file) edit = Menu(self, tearoff=0) edit.add_command(label="Undo") edit.add_separator() edit.add_command(label="Cut") edit.add_command(label="Copy") edit.add_command(label="Paste") self.add_cascade(label="Edit", menu=edit) help = Menu(self, tearoff=0) help.add_command(label="About", command=self.about) self.add_cascade(label="Help", menu=help) def exit(self): self.exit def about(self): messagebox.showinfo('PythonGuides', 'Python Guides aims at providing best practical tutorials') class MenuDemo(Tk): def __init__(self): Tk.__init__(self) menubar = MenuBar(self) self.config(menu=menubar) if __name__ == "__main__": ws=MenuDemo() ws.title('Python Guides') ws.geometry('300x200') ws.mainloop() |
Github:
https://github.com/mhcrnl/Python-Notepad



Comentarii
Trimiteți un comentariu