我试图将Enter键与按钮绑定。
在下面的代码中,我试图从条目小部件中获取条目,当bt按下按钮时,它将调用enter()获取条目的方法。
我也希望通过按Enter键来调用它,但没有得到想要的结果。
在输入小部件中输入的值未读取,调用了enter方法,仅在我的数据库中插入了一个空格
帮我找出我的问题,谢谢!
from tkinter import *
import sqlite3
conx = sqlite3.connect("database_word.db")
def count_index():
cur = conx.cursor()
count = cur.execute("select count(word) from words;")
rowcount = cur.fetchone()[0]
return rowcount
def enter(): #The method that I am calling from the Button
x=e1.get()
y=e2.get()
ci=count_index()+1
conx.execute("insert into words(id, word, meaning) values(?,?,?);",(ci,x,y))
conx.commit()
fr =Frame() #Main
bt=Button(fr) #Button declaration
fr.pack(expand=YES)
l1=Label(fr, text="Enter word").grid(row=1,column=1)
l2=Label(fr, text="Enter meaning").grid(row=2,column=1)
e1=Entry(fr)
e2=Entry(fr)
e1.grid(row=1,column=2)
e2.grid(row=2,column=2) …Run Code Online (Sandbox Code Playgroud) 当我尝试打印变量名时,它打印{{name}}而不是变量,我不知道我哪里出错了.
HTML:
<!DOCTYPE html>
<html ng-app="MyTestApp">
<head>
<title>Angular test</title>
<script type="text/javascript"> src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript"> src = "app.js"></script>
</head>
<body>
<div id="divx" ng-controller="MyTestController">
<input type="text" ng-model="name">
<h2>{{name}}</h2>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
(function () {
'use strict';
angular.module('MyTestApp', [])
.controller('MyTestController', function ($scope) {
$scope.name = "Angular";
$scope.sayHello = function () {
return "From function";
};
});
})();
Run Code Online (Sandbox Code Playgroud)