当pressed Tkinter的按钮保持沉没 [英] Tkinter button remains sunken when pressed

查看:287
本文介绍了当pressed Tkinter的按钮保持沉没的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道究竟在何处我的问题在于,它无论是在绑定,或它被调用的函数本身。

I don't know exactly where my problem lies, it is either in the bindings, or its the function being called itself.

我的按钮都出现一个labelFrame下,每个被伴随的条目中,从而使许多的csv文件可以由用户用于分析被装载,和文件路径是可见的。它由用户搜索这些文件可以在我的不同和未连接的项目文件夹存在。

My buttons all appear under a labelFrame and each are accompanied with an entry box, so that many csv files can be loaded by the user for analysis, and the filepaths are visible. It has to be searched by the user as these files can existed in my different and unconnected project folders.

这是一个例子按钮。

csv_type21 = Button(csvfiles, text = "Browse ...")
csv_type21.bind("<Button-1>", lambda event, obj = var21, tid = 21: find_cvsfile(event, obj, tid))

如果用户取消要找的文件,他们仍然凹陷,即使他们选择一个文件,它保持沉没。 (但在输入框并获得与文件路径更新)。

They remain sunken if the user cancels looking for the file, and even if they choose a file it stays sunken. (but the entry box does get updated with the filepath).

这是他们所说的功能,它要求一个CSV文件并将其保存为一个元组,这样我就可以跟踪哪些CSV是哪个。从那以后,我设置为STRINGVAR条目框,按钮符合陈述文件路径。

This is the function they call, it asks for a csv file and saves it as a tuple, so that I can keep track of which csv is which. After that I set the StringVar for the Entry box that the button is in line with to state the filepath.

def find_csvfile(event, obj, tid):
input_csvfile = askopenfile(initialdir = 'C:/',
                            filetypes = [("CSV File", "*.csv")],
                            title = 'Open CSV File for id ' + str(tid) + '...',
                            mode = 'r')
csv_data = tid, input_csvfile
filepath = input_csvfile.name
obj.set(filepath)

我试着摆弄不同的变量和参数,但没有工作负荷。我认为它是多个按钮调用相同的命令,但我不能肯定。

I've tried fiddling loads of different variables and arguments but nothing works. I think it has to be the multiple buttons calling the same command but I can't be sure.

任何帮助是AP preciated。

Any help is appreciated.

感谢。

推荐答案

通过删除绑定解决了问题。拉姆达命令被移动到按钮声明和事件参数从find_csvfile功能删除。该解决方案停止时pressed被凹陷的按钮。

Solved the problem by removing the binding. The lambda command was moved into the Button declaration and the "event" parameter removed from the find_csvfile function. This solution stops the buttons being sunken when pressed.

csv_type21 = Button(csvfiles, text = "Browse ...", command = lambda obj = var21, tid = 21: find_csvfile(obj, tid))

这篇关于当pressed Tkinter的按钮保持沉没的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆