在Python TKinter中将条目转换为字符串

时间:2017-12-23 22:55:46

标签: python tkinter

我正在尝试在TKinter中编写一个简单的日志记录应用程序。基本上我需要比较具有给定字符串的条目(正确的传递)。不幸的是,每当我输入密码时,“entry.get()”方法的结果都会改变输入 - 打印它返回:

def start_page():
    start_window = Tk()
    ent_1 = Entry(start_window)
    but_1 = Button(start_window, text='Login', command=partial(login, ent_1.get))
    but_1.grid(row=1,column=1)
    ent_1.grid(row=0, column=1)
    start_window.mainloop()

def login(input_password):
    correct_password = 'password'
    if correct_password == input_password:
        coefficient_calc()
        start_window.destroy()
    else:
        print('You typed:', input_password)
        print('Please type the correct password.')

代码

    public string GetGeneratedHTML(string url)
    {
        URL = url;
        Thread t = new Thread(new ThreadStart(WebBrowserThread));
        t.SetApartmentState(ApartmentState.STA);
        t.Start();
        t.Join();

        return GeneratedSource;
    }

    private void WebBrowserThread()
    {
        WebBrowser wb = new WebBrowser();
        wb.Navigate(URL);

        wb.DocumentCompleted +=
            new WebBrowserDocumentCompletedEventHandler(
                wb_DocumentCompleted);

        while (wb.ReadyState != WebBrowserReadyState.Complete)
            Application.DoEvents();

        //Added this line, because the final HTML takes a while to show up
        GeneratedSource = wb.Document.Body.InnerHtml;

        wb.Dispose();
    }`enter code here`

    private void wb_DocumentCompleted(object sender,
        WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser wb = (WebBrowser)sender;
        GeneratedSource = wb.Document.Body.InnerHtml;
    }

知道如何转换它或“获取”所需形式的条目?我发现很少有类似的话题,但没有人回答这个问题。

1 个答案:

答案 0 :(得分:1)

function _playDrive() { //dont work let audio = new Audio('http://docs.google.com/uc?export=download&id=ejemplo'); //is mp3 audio.controls = true; audio.crossOrigin = 'anonymous'; document.body.appendChild(audio); audio.play(); } function _playLocal() { //work let audio = new Audio('./mysong.mp3'); audio.controls = true; audio.crossOrigin = 'anonymous'; document.body.appendChild(audio); audio.play(); }的定义移到login()的范围内可以解决问题。无需将start_window()(和ent_1)传递到start_window,也无需使用login()

functools.partial