ITKeyword,专注技术干货聚合推荐

注册 | 登录

初识Dubbo 系列之8-Dubbo 集群容错

p0p0p0p01 2015-04-29

相关推荐:Dubbo 入门实例 本地伪集群测试Demo (推荐)

1.   概述   Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案 Dubbo是阿里巴巴SOA服务化治理方案的核心框架,

up vote 0 down vote favorite

I am trying to make a random "password" generator that will display a random string of characters in a tkinter entry widget. The problem is that everytime the button is clicked it generates a new entry widget instead of updating the current one. I tried moving and tweaking the "entry = g.en(text=word)" string but when I do that the button click doesn't produce anything in the box. I've been working at this for a while and I am yet to come up with a solution.

import random
from swampy.Gui import *
from Tkinter import *
import string

#----------Defs----------
def genpass():
    word = ''
    for i in range(10):
        word += random.choice(string.ascii_letters + string.punctuation + string.digits)
    entry = g.en(text=word)

#----------Main----------
g = Gui()
g.title('Password Helper')
label = g.la(text="Welcome to Password Helper! \n \n Choose from the options below to continue. \n")

button = g.bu(text='Generate a New Password', command=genpass)

g.mainloop()
python tkinter widget entry share asked Apr 17 '14 at 0:21 user3348004 7 2 add a comment  | 

1 Answer 1

active oldest votes up vote 0 down vote accepted

since you do this:

entry = g.en(text=word)

inside the function and the button calls the function each time it is pressed, You are going to get a new item each buttonpress.

that way the gui waits for the button to be pushed to run the command.

Secondly I think you will have a lot easier time with this if you remove the entry creation from the function. Rather I would suggest that you define the entry before calling the function, and have the function get/change the value (setting up with classes for a GUI is a big help). That way you won't be always creating a new entry box each button click.

相关推荐:(转)Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)

互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞

Try this:

from Tkinter import *
import random

class MYGUI:
    def __init__(self):

        root=Tk()
        root.title('Password Helper')
        label = Label(root, text="Welcome to Password Helper! \n \n Choose from the options below to continue. \n")
        self.button=Button(root, text='Generate a New Password', command=lambda: self.genpass())
        self.word=Label(root)

        label.pack()
        self.button.pack()
        self.word.pack()
        mainloop()

    genpass(self):
        word = ''
        for i in range(10):
            word += random.choice(string.ascii_letters + string.punctuation + string.digits)
        self.word['text']=word

if __name__ == '__main__':
    MYGUI()
share edited Apr 17 '14 at 3:44 answered Apr 17 '14 at 0:56 Amazingred 862 4 13      re: "that way the gui waits for the button to be pushed to run the command." That makes no sense. command=genpass gives precisely the same result as command=lambda: genpass() –  Bryan Oakley Apr 17 '14 at 2:10      My appologies. I spaced out that he was passing not invoking the function. I'm so used to using lambda to pass arguments to a command-function since I almost always use a single paramaterized callback rather than a unique callback per button. –  Amazingred Apr 17 '14 at 3:55 add a comment  | 

Your Answer

  draft saved draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name Email

Post as a guest

Name Email discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged python tkinter widget entry or ask your own question.

相关推荐:dubbo管理控制台安装及集成zookeeper集群部署

dubbo管理控制台开源部分主要包含:路由规则,动态配置,服务降级,访问控制,权重调整,负载均衡,等管理功能。1、下载dubbo地址:http://code.alibabatech

集群容错(+) (#)在集群调用失败时,Dubbo提供了多种容错方案,缺省为failover重试。各节点关系:这里的Invoker是Provider的一个可调用Service的抽象,Invoker

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。