Python Tkinter条目验证(Python Tkinter Entry validate)
我正在使用Tkinter在Python 3.6中编写一个程序,其中一个客户有多个(11)输入字段。 我希望这些输入字段只接受整数,并且能够定义最大字符数。
我已经有一个这样做的功能。 但是这个功能只适用于一个输入字段。 我已经尝试通过调用函数输入变量,以便例如更改另一个输入字段。 我无法做到这一点。
这是我有1个输入字段的功能。
def limitMuntgeld(self, *args): value = self.invoerM.get() if len(value) > 5: self.invoerM.set(value[:5]) if value.lower() in "abcdefghijklmnopqrstuvwxyz-=[];/": self.invoerM.set(value[:0])
这是与该函数一起使用的示例输入字段代码
self.invoerMuntgeld = Entry(self, font=('Arial', 14), textvariable=self.invoerM)
这与下面发布的输入字段中的跟踪相结合。
self.invoerM = StringVar() self.invoerM.trace('w', self.limitMuntgeld)
我也尝试了vcmd和validatecommand。 但是,没有好的结果。 我的endresult将是一个与所有输入字段一起工作的函数。 如果任何人有任何建议,我都耳朵!
I am writing a program in Python 3.6 using Tkinter where a customer has multiple(11) entry fields. I want these entry fields to only accept integers and also be able to define the maximum amount of characters.
I already have a function that does this. But this function only works for one entry field. I have tried entering variables with calling the function so it changes another entry field for example. I was not able to do this.
This is the function I have that works with 1 entry field.
def limitMuntgeld(self, *args): value = self.invoerM.get() if len(value) > 5: self.invoerM.set(value[:5]) if value.lower() in "abcdefghijklmnopqrstuvwxyz-=[];/": self.invoerM.set(value[:0])
This is the example entry field code that works with the function
self.invoerMuntgeld = Entry(self, font=('Arial', 14), textvariable=self.invoerM)
This is combined with a trace on the entry field posted below.
self.invoerM = StringVar() self.invoerM.trace('w', self.limitMuntgeld)
I have also tried it with vcmd and validatecommand. However, no good results. My endresult would be one function working with all entry fields. If anyone has any suggestions, I am all ears!
原文:https://stackoverflow.com/questions/49068813
最满意答案
检查一下。 我改变了var content = []; to var content = {};
$(document).on('click', '#guardarBtn', function (event) { var content= {}; $('.rowUpdate').each(function (i) { $(this).find('td').each(function (j, v) { if (j != 0) { var input = $("input", this), name = input.attr("name").substring(0, input.attr("name").length), value = input.val(); content[name] = value; // alert(JSON.stringify(content)); } }); alert(JSON.stringify(content)); // rows.push(content); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr class="rowUpdate"> <td>Corredor Feed</td> <td>Id Corrdor <input type="text" value="" class="validate" name="idcorreo"> </td> <td>Nombre <input type="text" value="" class="validate" name="nombre"> </td> <td>Email <input type="text" value="foo@bar.com" class="validate" name="email"> </td> <td>Empressa <input type="text" value="" class="validate" name="Empressa"> </td> <td>Pagina Web <input type="text" value="" class="validate" name="paginaWeb"> </td> <td>Telefono <input type="text" value="" class="validate" name="telephon"> </td> <td>Cellular <input type="text" value="" class="validate" name="cellular" /> </td> <td> <input type="submit" id="guardarBtn" value="Save" name="submitme"> </td> </tr> </table>
Check this one. I changed var content= []; to var content= {};
$(document).on('click', '#guardarBtn', function (event) { var content= {}; $('.rowUpdate').each(function (i) { $(this).find('td').each(function (j, v) { if (j != 0) { var input = $("input", this), name = input.attr("name").substring(0, input.attr("name").length), value = input.val(); content[name] = value; // alert(JSON.stringify(content)); } }); alert(JSON.stringify(content)); // rows.push(content); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr class="rowUpdate"> <td>Corredor Feed</td> <td>Id Corrdor <input type="text" value="" class="validate" name="idcorreo"> </td> <td>Nombre <input type="text" value="" class="validate" name="nombre"> </td> <td>Email <input type="text" value="foo@bar.com" class="validate" name="email"> </td> <td>Empressa <input type="text" value="" class="validate" name="Empressa"> </td> <td>Pagina Web <input type="text" value="" class="validate" name="paginaWeb"> </td> <td>Telefono <input type="text" value="" class="validate" name="telephon"> </td> <td>Cellular <input type="text" value="" class="validate" name="cellular" /> </td> <td> <input type="submit" id="guardarBtn" value="Save" name="submitme"> </td> </tr> </table>
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
jQuery:使整个表格行成为一个链接,除了一列之外(jQuery: Making entire table row a link, apart from one column)[2021-09-08]
你需要更深入一步并控制tr的元素,将一个点击处理程序绑定到每个不是tr最后一个的td : $(document).ready(function() { $('#movies tr').each(function(i,e) { $(e).children('td:not(:last)').click(function() { //here we are working on a td element, that's why we need ... -
如何在jQuery数组中保存行的每一列的内容(How to save the content of each column of a row in a jQuery array)[2021-02-06]
检查一下。 我改变了var content = []; to var content = {}; $(document).on('click', '#guardarBtn', function (event) { var content= {}; $('.rowUpdate').each(function (i) { $(this).find('td').each(function (j, v) { if (j != 0) { ... -
没关系。 VBA存在于Excel之外,例如在PowerPoint或Word中。 你没有行或列,但存在数组。 It doesn't matter. VBA exists outside of Excel, e.g. in PowerPoint or in Word. There you have no rows or columns, but arrays exist.
-
如果你为for循环交换这个for循环,它应该做的伎俩: for rownum in xrange(sh.nrows): row = sh.row_values(rownum) if row[0] == "clientegen": # Check if "clientgen" is the first element of the row finalarray = list(row) # If so, make a copy of it an ...
-
您没有终止您的ClientID电话: OnClientClick="javascript:return SaveItem(<% Eval("ID") %>, <% divrate.ClientID( %>);" 变为: OnClientClick="javascript:return SaveItem(<% Eval("ID") %>, <% divrate.ClientID() %>);" You didn't terminate your ClientID call: OnClientClick=" ...
-
像这样做: UPDATE DataTable SET Total = T1+T2+T3+T4+T5 但是,您可以让服务器使用computed column自动computed column 。 删除Total列并添加替换,如下所示: ALTER TABLE DataTable DROP COLUMN Total ALTER TABLE DataTable ADD Total as (T1+T2+T3+T4+T5) Do it like this: UPDATE DataTable SET Total ...
-
如何使用jquery在一列中添加两行的值?(How to addition two row's values in one single column using jquery?)[2022-11-10]
遍历所有.totalReceived值并添加它们的值。 然后将其放入.totalSale : var totalSale = 0; $(".totalReceived").each(function() { totalSale += parseInt($(this).val()); } $(".totalSale").val(totalSale); Loop over all the .totalReceived values and add their values. Then put this ... -
它不完全清楚你想在表中修改什么或者应该触发修改的内容。 但是,下面应该向您展示使其工作所需的概念。 请注意,我的表以一行开头。 在页面加载时,读取该行并将html作为数据属性存储在表本身上,然后删除该行。 稍后,当用户单击该按钮时,代码会复制存储的html并将该广告添加到该行。 我发现这种方法可以比使用字符串连接更容易管理统一的动态内容 var $table = $('#my-table') var $initialRow = $table.find('tbody tr:eq(0)'); $table. ...