- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试解决行号
在多个选项卡
中无法正常工作的问题。问题是,当我创建新选项卡时,其他选项卡的行号不起作用,但当前选项卡的行号起作用。 语法突出显示
也是如此。
我认为问题在于创建新选项卡时使用相同的变量,但我不知道如何解决此问题,并且我不确定这是否确实是问题所在。我还在考虑重新定义文本框,以及每次单击选项卡时与其关联的绑定(bind)。
下面是我的代码:
import tkinter as tk
import tkinter.filedialog
import traceback
import tkinter.ttk as ttk
from pygments import lex
from pygments.lexers import PythonLexer
import sys
import os
class TextLineNumbers(tk.Canvas):
def __init__(self, *args, **kwargs):
tk.Canvas.__init__(self, *args, **kwargs)
self.textwidget = None
def attach(self, text_widget):
self.textwidget = text_widget
def redraw(self, *args):
'''redraw line numbers'''
self.delete("all")
i = self.textwidget.index("@0,0")
while True:
dline= self.textwidget.dlineinfo(i)
if dline is None: break
y = dline[1]
linenum = str(i).split(".")[0]
self.create_text(5,y,anchor="nw", text=linenum, font=("Courier", 9))
i = self.textwidget.index("%s+1line" % i)
class CustomText(tk.Text):
def __init__(self, *args, **kwargs):
tk.Text.__init__(self, *args, **kwargs)
self.tk.eval('''
proc widget_proxy {widget widget_command args} {
# call the real tk widget command with the real args
set result [uplevel [linsert $args 0 $widget_command]]
# generate the event for certain types of commands
if {([lindex $args 0] in {insert replace delete}) ||
([lrange $args 0 2] == {mark set insert}) ||
([lrange $args 0 1] == {xview moveto}) ||
([lrange $args 0 1] == {xview scroll}) ||
([lrange $args 0 1] == {yview moveto}) ||
([lrange $args 0 1] == {yview scroll})} {
event generate $widget <<Change>> -when tail
}
# return the result from the real widget command
return $result
}
''')
self.tk.eval('''
rename {widget} _{widget}
interp alias {{}} ::{widget} {{}} widget_proxy {widget} _{widget}
'''.format(widget=str(self)))
self.comment = False
class Arshi(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.fileName = "Untitled Document"
self.content = ""
self.previousContent = ""
self.language = "Python"
self.row = "0"
self.column = "0"
self.startCol = 0
self.notebook = ttk.Notebook(self)
self.menubar()
self.bottomLabel()
self.createtext()
def deafultHighlight(self, argument):
self.content = self.text.get("1.0", tk.END)
self.lines = self.content.split("\n")
if (self.previousContent != self.content):
self.text.mark_set("range_start", self.row + ".0")
data = self.text.get(self.row + ".0", self.row + "." + str(len(self.lines[int(self.row) - 1])))
for token, content in lex(data, PythonLexer()):
self.text.mark_set("range_end", "range_start + %dc" % len(content))
self.text.tag_add(str(token), "range_start", "range_end")
self.text.mark_set("range_start", "range_end")
self.previousContent = self.text.get("1.0", tk.END)
def highlight(self, argument):
self.content = self.text.get("1.0", tk.END)
if (self.previousContent != self.content):
self.text.mark_set("range_start", "1.0")
data = self.text.get("1.0", self.text.index(tk.INSERT))
for token, content in lex(data, PythonLexer()):
self.text.mark_set("range_end", "range_start + %dc" % len(content))
self.text.tag_add(str(token), "range_start", "range_end")
self.text.mark_set("range_start", "range_end")
self.previousContent = self.text.get("1.0", tk.END)
def keypress(self, argument):
self.updateBottomLabel()
self.deafultHighlight("argument")
def configureTags(self, text):
text.tag_configure("Token.Keyword", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Constant", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Declaration", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Namespace", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Pseudo", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Reserved", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Type", foreground="#CC7A00")
text.tag_configure("Token.Name.Class", foreground="#003D99")
text.tag_configure("Token.Name.Exception", foreground="#003D99")
text.tag_configure("Token.Name.Function", foreground="#003D99")
text.tag_configure("Token.Operator.Word", foreground="#CC7A00")
text.tag_configure("Token.Comment", foreground="#B80000")
text.tag_configure("Token.Literal.String", foreground="#248F24")
def createtext(self):
self.notebook.pack(fill=tk.BOTH, expand=True)
self.tab1 = ttk.Frame(self.notebook)
self.text = CustomText(self.tab1, bd=0, font=("Courier", 9))
self.configureTags(self.text)
self.vsb = tk.Scrollbar(self.tab1, orient=tk.VERTICAL)
self.text.configure(yscrollcommand=self.vsb.set)
self.vsb.configure(command=self.text.yview)
self.linenumbers = TextLineNumbers(self.tab1, width=55)
self.linenumbers.attach(self.text)
self.vsb.pack(side=tk.RIGHT, fill=tk.Y)
self.linenumbers.pack(side="left", fill="y")
self.text.pack(side="right", fill="both", expand=True)
self.notebook.add(self.tab1, text=self.fileName)
self.text.bind("<<Change>>", self._on_change)
self.text.bind("<Configure>", self._on_change)
self.text.bind("<KeyRelease>", self.keypress)
self.text.bind("<Button-1>", self.keypress)
def addtab(self):
self.newTab = ttk.Frame(self.notebook)
self.text = CustomText(self.newTab, bd=0, font=("Courier", 9))
self.configureTags(self.text)
self.vsb = tk.Scrollbar(self.newTab, orient=tk.VERTICAL)
self.text.configure(yscrollcommand=self.vsb.set)
self.vsb.configure(command=self.text.yview)
self.linenumbers = TextLineNumbers(self.newTab, width=55)
self.linenumbers.attach(self.text)
self.vsb.pack(side=tk.RIGHT, fill=tk.Y)
self.linenumbers.pack(side="left", fill="y")
self.text.pack(side="right", fill="both", expand=True)
self.notebook.add(self.newTab, text="Untitled Document")
self.text.bind("<<Change>>", self._on_change)
self.text.bind("<Configure>", self._on_change)
self.text.bind("<KeyRelease>", self.keypress)
self.text.bind("<Button-1>", self.keypress)
def removetab(self):
numberOfTabs = self.notebook.index("end")
if numberOfTabs > 1:
tabIndex = self.notebook.index(self.notebook.select())
self.notebook.forget(tabIndex)
def run(self):
pass
def menubar(self):
self.menu = tk.Menu(self)
self.master.config(menu=self.menu)
self.fileMenu = tk.Menu(self.menu, font=("Courier", 9))
self.fileMenu.add_command(label="New Ctrl+N", command=self.newFile)
self.fileMenu.add_command(label="Open Ctrl+O", command=self.openFile)
self.fileMenu.add_command(label="Save Ctrl+S", command=self.saveFile)
self.fileMenu.add_command(label="Save As Ctrl+Shift+S", command=self.saveAsFile)
self.fileMenu.add_separator()
self.fileMenu.add_command(label="New Window", command=self.addtab)
self.fileMenu.add_command(label="Close Window", command=self.removetab)
self.fileMenu.add_separator()
self.fileMenu.add_command(label="Exit Alt+F4", command=self.close)
self.menu.add_cascade(label="File", menu=self.fileMenu)
self.runMenu = tk.Menu(self.menu, font=("Courier", 9))
self.runMenu.add_command(label="Run", command=self.run)
self.menu.add_cascade(label="Run", menu=self.runMenu)
def bottomLabel(self):
self.positionAndLanguage = tk.Label(self, text=" Ln: 1, Col: 0, Lang: Plain", anchor=tk.W, bg="#E7E7E7", font=("Courier New", 8))
self.positionAndLanguage.pack(fill=tk.X, side=tk.BOTTOM)
def updateBottomLabel(self):
self.row = self.text.index(tk.INSERT).split(".")[0]
self.column = self.text.index(tk.INSERT).split(".")[1]
self.positionAndLanguage["text"] = " Ln: {0}, Col: {1}, Lang: {2}".format(self.row, self.column, self.language)
def newFile(self):
self.fileName = "Untitled"
self.previousContent = ""
self.text.delete(0.0, tk.END)
def openFile(self):
try:
self.fileName = tk.filedialog.askopenfilename() #Asks user to open file
with open(self.fileName, 'r') as file:
self.content = file.read() #Reads content typed
self.text.delete(0.0, tk.END)
self.text.insert(0.0, self.content)
self.highlight(self)
except IOError as e:
print("Error reading file.")
except:
print("Unexpected error occured.")
def deleteContent(self, file):
file.seek(0)
file.truncate()
def saveFile(self):
self.content = self.text.get(0.0, tk.END)
try:
with open(self.fileName, 'w') as file:
self.deleteContent(file)
file.write(self.content)
except IOError as e:
print("Error reading file.")
except:
print("Unexpected error occured.")
def saveAsFile(self):
self.content = self.text.get(0.0, tk.END)
try:
self.fileName = tk.filedialog.asksaveasfilename()
if self.fileName != None:
with open(self.fileName, 'w') as file:
file.write(self.content)
except IOError as e:
print("Error reading file.")
except:
print("Unexcepted error occured.")
def close(self):
try:
os._exit(0)
except:
print(sys.exc_info()[0])
def _on_change(self, event):
self.linenumbers.redraw()
if __name__ == "__main__":
root = tk.Tk()
root.title("Arshi")
root.geometry("1024x600")
window = Arshi(root).pack(side="top", fill="both", expand=True)
root.mainloop()
最佳答案
是的,正如您所观察到的,问题是因为您总是在更改 linenumbers
到最新选项卡的行号,因此对于旧选项卡,即使 _on_change()
被调用时,它只会在新行号上调用重绘,而不会在旧行号上调用重绘。
我相信推进应用程序的正确方法是拥有另一个抽象级别,其中 Tab
本身就是一个完整的对象,每个选项卡都应该是一个不同的对象,并且应该在其自身中存储行号/文本。
示例 -
import tkinter as tk
import tkinter.ttk as ttk
class TextLineNumbers(tk.Canvas):
def __init__(self, *args, **kwargs):
tk.Canvas.__init__(self, *args, **kwargs)
self.textwidget = None
def attach(self, text_widget):
self.textwidget = text_widget
def redraw(self, *args):
'''redraw line numbers'''
self.delete("all")
i = self.textwidget.index("@0,0")
while True:
dline= self.textwidget.dlineinfo(i)
if dline is None: break
y = dline[1]
linenum = str(i).split(".")[0]
self.create_text(5,y,anchor="nw", text=linenum, font=("Courier", 9))
i = self.textwidget.index("%s+1line" % i)
class CustomText(tk.Text):
def __init__(self, *args, **kwargs):
tk.Text.__init__(self, *args, **kwargs)
self.tk.eval('''
proc widget_proxy {widget widget_command args} {
# call the real tk widget command with the real args
set result [uplevel [linsert $args 0 $widget_command]]
# generate the event for certain types of commands
if {([lindex $args 0] in {insert replace delete}) ||
([lrange $args 0 2] == {mark set insert}) ||
([lrange $args 0 1] == {xview moveto}) ||
([lrange $args 0 1] == {xview scroll}) ||
([lrange $args 0 1] == {yview moveto}) ||
([lrange $args 0 1] == {yview scroll})} {
event generate $widget <<Change>> -when tail
}
# return the result from the real widget command
return $result
}
''')
self.tk.eval('''
rename {widget} _{widget}
interp alias {{}} ::{widget} {{}} widget_proxy {widget} _{widget}
'''.format(widget=str(self)))
self.comment = False
class Tab:
def __init__(self, parent, filename):
self.parent = parent
self.filename = filename
self.tab1 = ttk.Frame(parent)
self.text = CustomText(self.tab1, bd=0, font=("Courier", 9))
self.vsb = tk.Scrollbar(self.tab1, orient=tk.VERTICAL)
self.text.configure(yscrollcommand=self.vsb.set)
self.vsb.configure(command=self.text.yview)
self.linenumbers = TextLineNumbers(self.tab1, width=55)
self.linenumbers.attach(self.text)
self.vsb.pack(side=tk.RIGHT, fill=tk.Y)
self.linenumbers.pack(side="left", fill="y")
self.text.pack(side="right", fill="both", expand=True)
parent.add(self.tab1, text=filename)
self.text.bind("<<Change>>", self._on_change)
self.text.bind("<Configure>", self._on_change)
def _on_change(self, event):
self.linenumbers.redraw()
class Window(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.fileName = "Untitled Document"
self.content = ""
self.previousContent = ""
self.language = "Python"
self.row = "0"
self.column = "0"
self.startCol = 0
self.notebook = ttk.Notebook(self)
self.tabs = []
self.menubar()
self.createtext()
def createtext(self):
self.notebook.pack(fill=tk.BOTH, expand=True)
t = Tab(self.notebook, self.fileName)
self.tabs.append(t)
def addtab(self):
t = Tab(self.notebook, self.fileName)
self.tabs.append(t)
def removetab(self):
numberOfTabs = self.notebook.index("end")
if numberOfTabs > 1:
tabIndex = self.notebook.index(self.notebook.select())
self.notebook.forget(tabIndex)
del self.tabs[tabIndex]
def menubar(self):
self.menu = tk.Menu(self)
self.master.config(menu=self.menu)
self.fileMenu = tk.Menu(self.menu, font=("Courier", 9))
self.fileMenu.add_command(label="New Window", command=self.addtab)
self.fileMenu.add_command(label="Close Window", command=self.removetab)
self.menu.add_cascade(label="File", menu=self.fileMenu)
if __name__ == "__main__":
root = tk.Tk()
root.title("Window")
root.geometry("1024x600")
window = Window(root).pack(side="top", fill="both", expand=True)
root.mainloop()
我创建了一个新类Tab
并从以前的方法复制代码,如 createtext
现在,当创建新选项卡时,我们只需要实例化 Tab
的对象即可类。
部分工作代码,适合您的情况 -
import tkinter as tk
import tkinter.filedialog
import traceback
import tkinter.ttk as ttk
from pygments import lex
from pygments.lexers import PythonLexer
import sys
import os
class TextLineNumbers(tk.Canvas):
def __init__(self, *args, **kwargs):
tk.Canvas.__init__(self, *args, **kwargs)
self.textwidget = None
def attach(self, text_widget):
self.textwidget = text_widget
def redraw(self, *args):
'''redraw line numbers'''
self.delete("all")
i = self.textwidget.index("@0,0")
while True:
dline= self.textwidget.dlineinfo(i)
if dline is None: break
y = dline[1]
linenum = str(i).split(".")[0]
self.create_text(5,y,anchor="nw", text=linenum, font=("Courier", 9))
i = self.textwidget.index("%s+1line" % i)
class CustomText(tk.Text):
def __init__(self, *args, **kwargs):
tk.Text.__init__(self, *args, **kwargs)
self.tk.eval('''
proc widget_proxy {widget widget_command args} {
# call the real tk widget command with the real args
set result [uplevel [linsert $args 0 $widget_command]]
# generate the event for certain types of commands
if {([lindex $args 0] in {insert replace delete}) ||
([lrange $args 0 2] == {mark set insert}) ||
([lrange $args 0 1] == {xview moveto}) ||
([lrange $args 0 1] == {xview scroll}) ||
([lrange $args 0 1] == {yview moveto}) ||
([lrange $args 0 1] == {yview scroll})} {
event generate $widget <<Change>> -when tail
}
# return the result from the real widget command
return $result
}
''')
self.tk.eval('''
rename {widget} _{widget}
interp alias {{}} ::{widget} {{}} widget_proxy {widget} _{widget}
'''.format(widget=str(self)))
self.comment = False
class Tab:
def __init__(self, parent, filename, parentwindow):
self.fileName = "Untitled Document"
self.content = ""
self.previousContent = ""
self.parentwindow = parentwindow
self.language = "Python"
self.parent = parent
self.filename = filename
self.tab1 = ttk.Frame(parent)
self.text = CustomText(self.tab1, bd=0, font=("Courier", 9))
self.vsb = tk.Scrollbar(self.tab1, orient=tk.VERTICAL)
self.text.configure(yscrollcommand=self.vsb.set)
self.vsb.configure(command=self.text.yview)
self.linenumbers = TextLineNumbers(self.tab1, width=55)
self.linenumbers.attach(self.text)
self.vsb.pack(side=tk.RIGHT, fill=tk.Y)
self.linenumbers.pack(side="left", fill="y")
self.text.pack(side="right", fill="both", expand=True)
parent.add(self.tab1, text=filename)
self.bottomLabel()
self.text.bind("<<Change>>", self._on_change)
self.text.bind("<Configure>", self._on_change)
self.text.bind("<KeyRelease>", self.keypress)
self.text.bind("<Button-1>", self.keypress)
def deafultHighlight(self, argument):
self.content = self.text.get("1.0", tk.END)
self.lines = self.content.split("\n")
if (self.previousContent != self.content):
self.text.mark_set("range_start", self.row + ".0")
data = self.text.get(self.row + ".0", self.row + "." + str(len(self.lines[int(self.row) - 1])))
for token, content in lex(data, PythonLexer()):
self.text.mark_set("range_end", "range_start + %dc" % len(content))
self.text.tag_add(str(token), "range_start", "range_end")
self.text.mark_set("range_start", "range_end")
self.previousContent = self.text.get("1.0", tk.END)
def highlight(self, argument):
self.content = self.text.get("1.0", tk.END)
if (self.previousContent != self.content):
self.text.mark_set("range_start", "1.0")
data = self.text.get("1.0", self.text.index(tk.INSERT))
for token, content in lex(data, PythonLexer()):
self.text.mark_set("range_end", "range_start + %dc" % len(content))
self.text.tag_add(str(token), "range_start", "range_end")
self.text.mark_set("range_start", "range_end")
self.previousContent = self.text.get("1.0", tk.END)
def keypress(self, argument):
self.updateBottomLabel()
self.deafultHighlight("argument")
def _on_change(self, event):
self.linenumbers.redraw()
def bottomLabel(self):
self.positionAndLanguage = tk.Label(self.parentwindow, text=" Ln: 1, Col: 0, Lang: Plain", anchor=tk.W, bg="#E7E7E7", font=("Courier New", 8))
self.positionAndLanguage.pack(fill=tk.X, side=tk.BOTTOM)
def updateBottomLabel(self):
self.row = self.text.index(tk.INSERT).split(".")[0]
self.column = self.text.index(tk.INSERT).split(".")[1]
self.positionAndLanguage["text"] = " Ln: {0}, Col: {1}, Lang: {2}".format(self.row, self.column, self.language)
class Arshi(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.fileName = "Untitled Document"
self.content = ""
self.previousContent = ""
self.language = "Python"
self.row = "0"
self.column = "0"
self.startCol = 0
self.tabs = []
self.notebook = ttk.Notebook(self)
self.menubar()
#self.bottomLabel()
self.createtext()
def deafultHighlight(self, argument):
self.content = self.text.get("1.0", tk.END)
self.lines = self.content.split("\n")
if (self.previousContent != self.content):
self.text.mark_set("range_start", self.row + ".0")
data = self.text.get(self.row + ".0", self.row + "." + str(len(self.lines[int(self.row) - 1])))
for token, content in lex(data, PythonLexer()):
self.text.mark_set("range_end", "range_start + %dc" % len(content))
self.text.tag_add(str(token), "range_start", "range_end")
self.text.mark_set("range_start", "range_end")
self.previousContent = self.text.get("1.0", tk.END)
def highlight(self, argument):
self.content = self.text.get("1.0", tk.END)
if (self.previousContent != self.content):
self.text.mark_set("range_start", "1.0")
data = self.text.get("1.0", self.text.index(tk.INSERT))
for token, content in lex(data, PythonLexer()):
self.text.mark_set("range_end", "range_start + %dc" % len(content))
self.text.tag_add(str(token), "range_start", "range_end")
self.text.mark_set("range_start", "range_end")
self.previousContent = self.text.get("1.0", tk.END)
def keypress(self, argument):
self.updateBottomLabel()
self.deafultHighlight("argument")
def configureTags(self, text):
text.tag_configure("Token.Keyword", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Constant", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Declaration", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Namespace", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Pseudo", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Reserved", foreground="#CC7A00")
text.tag_configure("Token.Keyword.Type", foreground="#CC7A00")
text.tag_configure("Token.Name.Class", foreground="#003D99")
text.tag_configure("Token.Name.Exception", foreground="#003D99")
text.tag_configure("Token.Name.Function", foreground="#003D99")
text.tag_configure("Token.Operator.Word", foreground="#CC7A00")
text.tag_configure("Token.Comment", foreground="#B80000")
text.tag_configure("Token.Literal.String", foreground="#248F24")
def createtext(self):
self.notebook.pack(fill=tk.BOTH, expand=True)
t = Tab(self.notebook, self.fileName, self)
self.tabs.append(t)
def addtab(self):
t = Tab(self.notebook, self.fileName, self)
self.tabs.append(t)
def removetab(self):
numberOfTabs = self.notebook.index("end")
if numberOfTabs > 1:
tabIndex = self.notebook.index(self.notebook.select())
self.notebook.forget(tabIndex)
def run(self):
pass
def menubar(self):
self.menu = tk.Menu(self)
self.master.config(menu=self.menu)
self.fileMenu = tk.Menu(self.menu, font=("Courier", 9))
self.fileMenu.add_command(label="New Ctrl+N", command=self.newFile)
self.fileMenu.add_command(label="Open Ctrl+O", command=self.openFile)
self.fileMenu.add_command(label="Save Ctrl+S", command=self.saveFile)
self.fileMenu.add_command(label="Save As Ctrl+Shift+S", command=self.saveAsFile)
self.fileMenu.add_separator()
self.fileMenu.add_command(label="New Window", command=self.addtab)
self.fileMenu.add_command(label="Close Window", command=self.removetab)
self.fileMenu.add_separator()
self.fileMenu.add_command(label="Exit Alt+F4", command=self.close)
self.menu.add_cascade(label="File", menu=self.fileMenu)
self.runMenu = tk.Menu(self.menu, font=("Courier", 9))
self.runMenu.add_command(label="Run", command=self.run)
self.menu.add_cascade(label="Run", menu=self.runMenu)
def bottomLabel(self):
self.positionAndLanguage = tk.Label(self, text=" Ln: 1, Col: 0, Lang: Plain", anchor=tk.W, bg="#E7E7E7", font=("Courier New", 8))
self.positionAndLanguage.pack(fill=tk.X, side=tk.BOTTOM)
def updateBottomLabel(self):
self.row = self.text.index(tk.INSERT).split(".")[0]
self.column = self.text.index(tk.INSERT).split(".")[1]
self.positionAndLanguage["text"] = " Ln: {0}, Col: {1}, Lang: {2}".format(self.row, self.column, self.language)
def newFile(self):
self.addtab()
def openFile(self):
try:
self.fileName = tk.filedialog.askopenfilename() #Asks user to open file
with open(self.fileName, 'r') as file:
self.content = file.read() #Reads content typed
self.text.delete(0.0, tk.END)
self.text.insert(0.0, self.content)
self.highlight(self)
except IOError as e:
print("Error reading file.")
except:
print("Unexpected error occured.")
def deleteContent(self, file):
file.seek(0)
file.truncate()
def saveFile(self):
self.content = self.text.get(0.0, tk.END)
try:
with open(self.fileName, 'w') as file:
self.deleteContent(file)
file.write(self.content)
except IOError as e:
print("Error reading file.")
except:
print("Unexpected error occured.")
def saveAsFile(self):
self.content = self.text.get(0.0, tk.END)
try:
self.fileName = tk.filedialog.asksaveasfilename()
if self.fileName != None:
with open(self.fileName, 'w') as file:
file.write(self.content)
except IOError as e:
print("Error reading file.")
except:
print("Unexcepted error occured.")
def close(self):
try:
os._exit(0)
except:
print(sys.exc_info()[0])
def _on_change(self, event):
self.linenumbers.redraw()
if __name__ == "__main__":
root = tk.Tk()
root.title("Arshi")
root.geometry("1024x600")
window = Arshi(root).pack(side="top", fill="both", expand=True)
root.mainloop()
目前,open()
不起作用,并且每个选项卡的底部标签都会出现重复,您应该考虑如何解决这些问题。可以移出的底部标签 Tab
类(class)返回Arshi
,然后在 Tab
之间进行一些沟通类和Arshi
当选项卡更改时,相应地更改底部标签。
此外,打开应该打开一个新选项卡,以便您可以轻松地进行操作。我还建议您理解完整的代码,然后在您的代码中使用它,而不是仅仅复制粘贴。
关于python - 行号和语法突出显示在不同选项卡上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32064460/
给定一个 Option[Future[Option[Int]]] : scala> val x: Option[Future[Option[Int]]] = Some ( Future ( Some
如果我理解正确,EitherT[Option,A,B] 应该与 Option[Either[A,B]] 相同,但编译器不同意.以下代码编译失败: def f[A,B] = implicitly[Eit
我刚开始在使用 parcel.js 构建静态 Assets 时遇到此错误。它在本地工作,但我在 Heroku 上的构建出错,我不确定它是否相关。 最佳答案 得到同样的问题。通过将 core-js 安装
当我生成 Telerik Report 时,只有 Export PDF 可用。即使我将 docx 和 xlsx 的配置设置为 true。这是我在网络配置中的配置。
我的 iTunesConnect 应用程序显示 Apple Pay 选项。我正在使用布伦特里。 即使我们没有在应用程序中使用 Apple Pay 功能。 有人可以帮我解决如何在我的 itunesCon
我正在 Raspbian 中从命令行运行以下查询: mysql -u $NAME -p $PASS Tweets -e "SELECT count(*) FROM raw_tweets;" 它输出以下
我正在尝试使用 ffmpeg(在 linux 下)为视频添加一个小标题。所以,我使用: ffmpeg -i hk.avi -r 30000/1001 -metadata title="SOF" hk_
我正在尝试使用 ffmpeg 使用 ffserver 流式传输视频。您将在 ffserver1.conf 文件下方找到 ffmpeg 命令的日志输出。 其中一个错误引用了预设,每次我尝试使用预设时,我
我正在尝试对 Option 使用 fold 或 map 操作而不是 match。 我有一个选项 val ao: Option[String] = xxxx 和一个函数 f: (String => Fu
Dockerfile documentation表示有可能通过 --platform FROM 中的选项像这样的指令: FROM [--platform=] [AS ] 在我的 dockerfile
我不确定“属性(property)”或“选项”是否是正确的术语,但这是我需要弄清楚的。 鉴于以下情况: ' $.fileup({ url: '/file/upload',
我正在尝试使用 jQuery 检查是否选择了值 = 1 的选择选项,然后将类添加到某些元素。但有些东西不起作用。可以请人看一下代码吗? 我的代码: Reservation
我对 VIM 中的这些感到困惑。有些事情需要设置,而另一些则让。 而且,我如何检查某个选项。我知道这是一个选项,因为我使用 set 来更改它。 例如,如何检查当前文件类型选项是否为 java? 最佳答
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我在看《Professional F# 2.0》一书作者展示如下代码 let a string : option = None if a.IsNone then System.Console.
我习惯使用方法顶部的 java 样板检查输入参数: public static Boolean filesExist(String file1, String file2, String file3
假设我有一串 "Insert Post -title Some PostTitle -category 2 -date-posted 2013-02:02 10:10:10" 我一直在尝试做的是将这个
从 1.3.70 EAP 开始,在 org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions 这是 var useIR: kotlin.Boolean 哪个激活
我无法获取订购捆绑商品的所有子产品及其选项。这可能吗? 最佳答案 以下是您如何找出哪些产品应与所有其他项目一起附加到列表中的捆绑产品中的方法: foreach ($order->getAllItems
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我是一名优秀的程序员,十分优秀!