每次我想运行此代码时,我都会遇到分段错误:
from Tkinter import *
def gui():
root=Tk()
menubar=Menu(root)
filemenu=Menu(menubar,tearoff=0)
filemenu.add_command(label='New',command=gui)
filemenu.add_command(label='Close',command=root.quit)
menubar.add_cascade(label='File',menu=filemenu)
helpmenu=Menu(menubar,tearoff=1)
helpmenu.add_separator()
helpmenu.add_command(label="Help")#ajouter commande
helpmenu.add_command(label='About...')#ajouter commande
helpmenu.add_cascade(label='Help',menu=helpmenu)
root.mainloop()
gui()
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?我该怎么办 ?先感谢您.MFF
我正在尝试用Python制作拼字游戏.机架(7个字母所在的位置)是一个列表,其中我附加了7次tk.StringVar()每次玩家想要删除一个单词时,我必须从机架上取下这些字母.这是我的问题.由于我可以将drop字样和机架字母相关联,因此我创建了一个临时列表,我从初始机架中附加每个StringVar.get().然后我创建了一个代码,用空字符串''更改掉落的字母,因为我可以将初始机架与临时列表相关联.这是我的代码
def defausse_rack_prov(word,rack_prov):
word=word.get()
for i in word:
if i.upper() in rack_prov:
rack_prov[rack_prov.index[i]]='' #This is the problematic line
return rack_prov
Run Code Online (Sandbox Code Playgroud)
我一直在
TypeError: 'builtin_function_or_method' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
我该怎么办 ?谢谢 :)
如何在vim中突出显示一种颜色和空格的标签?
我知道如何仅突出显示标签或仅突出显示空格.而且我不知道如何为空格和制表符分别选择颜色.
很多人写道,这个版本get_len更快:
int get_len(char* str)
{
char *cpy;
cpy = str;
while (*cpy)
{
++cpy;
}
return (cpy - str);
}
Run Code Online (Sandbox Code Playgroud)
比这个:
int get_len2(char* str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return i;
}
Run Code Online (Sandbox Code Playgroud)
但是当我检查运行时间时,第二个看起来更快......
所以我的问题是为什么?
这是主要的功能测试:
int main()
{
clock_t begin, end;
double time_spent;
begin = clock();
printf("%d\n", get_len("HEEEEY"));
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%f\n", time_spent);
begin = clock();
printf("%d\n", get_len2("HEEEEY"));
end = clock();
time_spent = (double)(end - …Run Code Online (Sandbox Code Playgroud) 我想在另一个之后执行许多功能.每个函数返回True或False.因此,如果一个函数返回True,我想执行下一个函数.等等...
所有函数都没有必要相同的参数.
现在我有类似的东西:
res=function1()
if res:
res=function2()
if res:
res=function2()
Run Code Online (Sandbox Code Playgroud)
它继续执行20个功能.有一个更好的方法吗 ?
先感谢您...
我想改变页面的CSS.我看到两种方法:
使用该Jquery .css函数更改html中的每个标记.例如:
$("body").css("background : red")
Run Code Online (Sandbox Code Playgroud)
或者禁用当前的css样式表并启用新的样式表.
例:
function switch_style ( css_title )
{
// You may use this script on your site free of charge provided
// you do not remove this notice or the URL below. Script from
// http://www.thesitewizard.com/javascripts/change-style-sheets.shtml
var i, link_tag ;
for (i = 0, link_tag = document.getElementsByTagName("link") ;
i < link_tag.length ; i++ ) {
if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) &&
link_tag[i].title) {
link_tag[i].disabled = true ;
if (link_tag[i].title == css_title) …Run Code Online (Sandbox Code Playgroud) 我开始了一个项目.在编写指令时,我们可以使用以下命令行测试程序:
cat test.txt> test.py
但我没有输出.据我所知,它应该给我一个输出.
test.txt文件如下所示:
1
3
4
2
5
6
7
1
1
8
9
3
4
5
1
-1
Run Code Online (Sandbox Code Playgroud)
test.py文件看起来像:
for i in range(16):
var=raw_input("type something : ")
print var
Run Code Online (Sandbox Code Playgroud)
我正在使用此命令行将test.txt文件的内容重定向到运行时的test.py文件.
我已经阅读了有关cat命令的文档.
请问你能帮帮我吗 ?
换句话说,cat命令应该如何模拟用户?我想我必须在我的python文件中改变一些东西.
提前谢谢,Mff