小编sig*_*980的帖子

限制Tkinter Entry小部件中的值

我需要将Entry小部件中的值限制为仅限数字.我实施的方式是:

import numpy as np
from Tkinter import *;
import tkMessageBox;

class window2:

    def __init__(self,master1):

        self.panel2=Frame(master1)
        self.panel2.grid()

        self.button2=Button(self.panel2,text="Quit",command=self.panel2.quit)
        self.button2.grid()

        self.text1=Entry(self.panel2)
        self.text1.grid()
        self.text1.bind('<KeyPress>', self.keybind1)
        self.text1.focus()

    def keybind1 (self,event):
        if event.int in np.linspace(0,9,10):
            print event.int


root1=Tk()
window2(root1)
root1.mainloop()
Run Code Online (Sandbox Code Playgroud)

我不断收到Event实例没有属性'int'的错误消息.我该怎么办?

python validation tkinter

10
推荐指数
3
解决办法
4万
查看次数

在eclipse中导入matplotlib

我在Ecplise中运行pydev(Python 2.7).Numpy和tkinter工作正常,但我安装了matplotlib,出于某种原因,当我尝试时

来自matplotlib import*

我得到了没有找到的回复.我将带有模块的文件夹添加到PythonPath,但不断获得相同的消息.我究竟做错了什么?

python matplotlib pydev

3
推荐指数
1
解决办法
9586
查看次数

在Tkinter中使用pygame功能

我想在我在Tkinter中制作的GUI中使用pygame(精灵图形)中的一些功能.我知道OcempGUI,但我更喜欢坚持使用Tkinter,只需使用pygame中的一些模块.类似但不完全相同.这有可能吗?什么是潜在的问题(事件循环)?

user-interface pygame tkinter

3
推荐指数
1
解决办法
4140
查看次数

循环在Tkinter的小部件

这是我正在考虑的问题:

我在框架中有许多类似的小部件(例如Lables).我在算法的每次迭代中更新它们(root.update() 在相关函数中使用.我想知道的是,如何遍历每个Label.

当然,它们是用类似的东西创建的

self.var1=IntVar()
self.lab1=Label(frame,textvariable=self.var1)
self.lab1.grid() 
Run Code Online (Sandbox Code Playgroud)

因此每个标签都被命名为lab1,lab2等.我非常确定应该有更好的方法来命名它们,这样我就不必明确地调用每个名字,或以某种方式循环它们.

python loops tkinter widget

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