我定义了一个简单的a
喜欢
b
此列表将显示为var exports = module.exports = {};
exports.getData = function() {
var Q = require('q');
var result = 0;
// Promise 1
var deferred = Q.defer();
var promise1 = Q.fcall(function() {
setTimeout( function(){console.log('hi');deferred.resolve(9);}, 1000 );
return deferred.promise;
});
promise1.then(function(contents) {
result = result + contents;
console.log(contents);
});
// promise 2
var deferred2 = Q.defer();
var promise2 = Q.fcall(function() {
setTimeout( function(){console.log('hi');deferred2.resolve(10);}, 1000 );
return deferred2.promise;
});
promise2.then(function(contents) {
result = result + contents;
console.log(contents);
});
// promise3
var deferred3 = Q.defer();
var promise3 = Q.fcall(function() {
setTimeout( function(){console.log('hi');deferred3.resolve(11);}, 1000 );
return deferred3.promise;
});
promise3.then(function(contents) {
result = result + contents;
console.log(contents);
});
};
作为默认值,这很好。但是也定义了命令按钮,最终需要更改它以显示另一个可用选项(比如var x = require('./example5.js');
var result = x.getData();
console.log(' Result is ' + result);
)。如何实现这一目标?
答案 0 :(得分:4)
您已经找到了设置默认值并进行更改的方法。您拥有与v
小部件相关联的OptionMenu
变量。如果您在任何时候再次更改该变量的值,它将更新您的小部件:
import tkinter as tk
root = tk.Tk()
optionList = ('a', 'b', 'c')
v = tk.StringVar()
v.set(optionList[0]) # Here is the initially selected value
om = tk.OptionMenu(root, v, *optionList)
om.pack()
v.set(optionList[2]) # This one will be the final selected value
root.mainloop()