小编Ema*_*msi的帖子

Java 中使用 toString 和 Equals 方法的多态性对我来说毫无意义?

鉴于以下代码:

class Kitten {
    private String name = "";

    public Kitten(String name) {
        name = name;
    }

    public String toString() {
        return "Kitten: " + name;
    }

    public boolean equals(Object other) {
        if (this == other) return true;
        if (null == other) return false;
        if (!(other instanceof Kitten)) return false;
        Kitten that = (Kitten) other;
        return this.name.equals(that.name);
    }
}

//Assume that the Following lines have already been executed

Object maggie = new Kitten("Maggie");
Object fiona = new Kitten("Fiona");
Object fiona2 …
Run Code Online (Sandbox Code Playgroud)

java polymorphism

4
推荐指数
1
解决办法
77
查看次数

在 pySimpleGUI 中运行复杂的代码?

我正在尝试在 GUI 内运行一些代码,在获得一些文本输入后运行一个函数。然而,我尝试运行的函数实际上非常复杂,因此当它运行时,它会使整个 GUI 冻结 10-15 秒,然后再继续。

我怎样才能做到这样,当我点击运行按钮时,它不会冻结整个 GUI 等待函数完成?

我确实知道有一种方法可以使函数线程化,但是,我不知道如何实现?

如果有一个例子来说明如何包装一个函数以使其成为线程函数,那就太好了。

下面的代码给出了我正在处理的问题的示例。

import PySimpleGUI as sg
import time

def simple_gui():
    layout = [  [sg.T('try clicking "do something" and move the window')],
                [sg.Button('do something'), sg.Button('Exit')] ]
    w = sg.Window('test', layout)
    
    while True:
       events, values = w.read()
       if events == 'do something':
           # If you hit the button "do something":
           #    run a function that takes 30 seconds to complete.
           time.sleep(30)

       if events == sg.WIN_CLOSED or events == 'Exit':
            break
    
    w.close() …
Run Code Online (Sandbox Code Playgroud)

python user-interface

3
推荐指数
1
解决办法
2506
查看次数

标签 统计

java ×1

polymorphism ×1

python ×1

user-interface ×1