小编Cri*_*spy的帖子

Python,Tkinter,Checkbutton:有没有办法检查开/关值

我想要做的是设置if语句来检查一个checkbuttons值是打开还是关闭

我在想的是这样的

from Tkinter import *

def checkbutton_value():
    #If statement here
    #is their something like 

    #if checkbox_1.onvalue == True:
    #   checkbox_2.deselect()

    #if checkbox_1.varible == checkbox_1.onvalue:
    #   checkbox_2.deselect()

    print 'Need Help on lines 7-8 or 10-11'

root=Tk()

checkbox_1 = Checkbutton(root, text='1   ', command=checkbutton_value).pack()
checkbox_2 = Checkbutton(root, text='2   ', command=checkbutton_value).pack()

checkbox_3 = Checkbutton(root, text='QUIT', command=quit).pack()

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

python checkbox if-statement tkinter

0
推荐指数
1
解决办法
2万
查看次数

Python词典:排序麻烦

我以为我发现要通过清除它来排序字典,然后按照我想要的顺序重新组装它,但由于某种原因它按照它开始的方式重新排序.

这是代码,如果有人可以帮助我

from operator import itemgetter

n = {}
d = {
 'a': ['2', 'ova', 'no'], 
 'b': ['23', 'movie', 'yes'], 
 'c': ['5', 'show', 'yes'], 
 'd': ['17', 'ova', 'yes'], 
 'e': ['1', 'movie', 'no']
}

for i in d:
    print i, d[i]

print '\n'

l = d.items()
l.sort(key=itemgetter(1)) #l is now sorted by the value of the string holding the integers
d.clear()

for i in l:
    print i[0], i[1]
    d[i[0]] = i[1] 

print '\n'

for i in d:
    print i, d[i] #Why …
Run Code Online (Sandbox Code Playgroud)

python sorting dictionary list

0
推荐指数
1
解决办法
149
查看次数

Tkinter 标题栏选项

Tkinter 中有没有办法编辑标题栏?诸如背景颜色前景色、标题栏大小等选项。这是我正在处理的一个类的代码,我正在寻找使标题栏与框架匹配的方法。

#CreateFile
from Tkinter import *

class CreateFile(Tk):
    def __init__(self, model):
        self.model=model
        myfont = ("Arial", 11, "bold")
        Tk.__init__(self)
        self.title('Create New File')

        self.resizable(0,0)
        frame = Frame(self,bg='black')
        self.lbl=Label(frame,text='Name: ',bg='black',fg='yellow')
        self.lbl.grid(row=0,column=0)
        self.file_entry=Entry(frame,width=30,font=myfont,bg='black',fg='yellow')
        self.file_entry.bind('<Control-a>',self.select_all)
        self.file_entry.grid(row=0,column=1)
        self.create_btn=Button(frame,text='Create',bg='black',fg='yellow')
        self.create_btn.grid(row=0,column=2,padx=10)    
        frame.grid()
        self.mainloop()

    def select_all(self,event):
        print 'd'

model=None
createFile = CreateFile(model)
Run Code Online (Sandbox Code Playgroud)

editor tkinter titlebar options

0
推荐指数
1
解决办法
4362
查看次数

二元AND运算符的解释

有人可以解释按位,二进制 AND 运算符( & )的目的以及如何使用它?我正在研究创建isprime函数的不同方法并遇到了这个问题。

def isprime(n):
    # make sure n is a positive integer
    n = abs(int(n))
    # 0 and 1 are not primes
    if n < 2:
        return False
    # 2 is the only even prime number
    if n == 2: 
        return True    
    # all other even numbers are not primes
    if not n & 1: 
        return False
    # range starts with 3 and only needs to go up the squareroot of n
    # for all …
Run Code Online (Sandbox Code Playgroud)

python bitwise-operators

0
推荐指数
1
解决办法
1462
查看次数

jQuery: How to wait until fadeTo(or any other effect) finishes before executing code

I'm making a news board that fades the news in and out. When the element fades out the content gets deleted, when it fades back in there is new content in its place. This works, just the timing is off. The new content that should only appear when the old content has faded away, appears as the element is fading. Is there a way to wait until this is done?

$(document).ready(function() {
    var counter = 0;
    var slides = ['<p>Track …
Run Code Online (Sandbox Code Playgroud)

javascript time jquery wait

0
推荐指数
1
解决办法
710
查看次数

jQuery:添加了类但忽略了margin-top样式

我在悬停时切换一个元素上的类,该类添加得很好,但margin-top似乎只是被忽略了.如何使margin-top样式正常工作?我的代码在这里@ jsfiddle.代码只是一个片段.

CSS:

#nav ul {
    display: inline;
    list-style: none;
}
#nav li {
    float:left;
    width:100px;
    height:100px;
    margin-top:0px;
    margin-right:50px;
}
.hover {
    background-color: red;
    margin-top: 100px;
}
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$('#nav ul a li').hover(function () {
    $(this).toggleClass('hover');
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="nav">
    <ul>    <a href="">
                <li>

                    <h3>title</h3>
                    <p>description.</p>
                </li>
            </a>
    <a href="">
                <li>
                    <h3>title</h3>
                    <p>description.</p>
                </li>
            </a>
    <a href="">
                <li>
                    <h3>title</h3>
                    <p>description.</p>
                </li>
            </a>

    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

css jquery

0
推荐指数
2
解决办法
254
查看次数