我正在考虑Tkinter菜单标签(命令)的快捷方式.在Mac上,与cmd⌘的组合很常见.
到目前为止我只找到了self.bind_all("<Control-q>", self.quit).如何实施cmd⌘快捷方式?
然后再考虑一下 - 一旦应用程序完成 - 将其转换为Windows和Mac应用程序的可执行文件可能会在使用cmd时遇到困难⌘?处理这个问题的最佳方法是什么?
我想在Tkinter菜单命令上创建一个大文本,并通过进度条提供视觉支持.虽然进度条要在后续耗时循环之前启动,但只有在创建和显示大文本后才会显示进度条.
def menu_bar(self):
self.create_menu.add_command(label="Create large file",
command=self.create_large_file)
def create_large_file(self):
self.progressbar = ttk.Progressbar(self.master, mode='indeterminate')
self.progressbar.pack()
self.progressbar.start()
self.text.delete(1.0, 'end')
self.file_content = []
i = 0
while i < 2000000:
line = lfd.input_string
self.file_content.append(line + "\n")
i += 1
self.file_content = ''.join(self.file_content)
self.text.insert(1.0, self.file_content)
Run Code Online (Sandbox Code Playgroud) 我想建立一个新的列表,其中遗漏了初始列表的每个第n个元素,例如:
来自['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh']
make ['second', 'third', 'fifth', 'sixth'因为n = 3
怎么做?它是 - 首先 - 通过建立一个新的列表而不是试图删除来实现这一点是正确的吗?对于后者,我尝试了deque,rotate但最终混乱.
为了建立一个新的列表,我正在尝试使用,range(1,len(list),n)但这是要删除的元素位置,而不是要为新列表保留的元素位置.
我如何得到我想要的清单?
下面的代码有什么问题?我认为由于最后一个参数,它在调用菜单栏时抛出异常?
该应用程序应该是一个简单的文本编辑器,我想在单独的类中进行菜单声明.当我运行脚本时,文本字段成功生成,但没有菜单栏.当我退出应用程序时,会出现以下错误消息.
"""
Traceback (most recent call last):
File "Editor_play.py", line 41, in <module>
menu = Menubar(window, textfield.text)
File "Editor_play.py", line 20, in __init__
menubar = Menu(window)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2580, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1974, in __init__
_tkinter.TclError: this isn't a Tk applicationNULL main window
"""
from Tkinter import *
import tkFileDialog
class Textfield(object):
def __init__(self, window):
self.window = window
window.title("text editor")
self.scrollbar = Scrollbar(window)
self.scrollbar.pack(side="right",fill="y")
self.text = Text(window,yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.text.yview)
self.text.pack()
window.mainloop()
class Menubar(object):
def __init__(self, window, text): …Run Code Online (Sandbox Code Playgroud)