簡體   English   中英

如何從 GUI 檢索文本框中的輸入並將其存儲在變量中?

[英]How do I retrieve the input into my text box from my GUI and store it in a variable?

我是 Python 新手,需要一些幫助。 我需要幫助從我的文本框中檢索輸入並將其存儲在變量中。 這就是我目前為我的 GUI 所擁有的。 基本上我只想從每個文本框中返回輸入並將其存儲在一個變量中。 我想,自從我使用“return like_userInput”以來,我只能將輸入存儲在該變量中,但它不起作用。 任何信息將不勝感激。 我對編程仍然非常陌生,希望您能給我提供任何反饋。

import tkinter as tk
from tkinter import ttk
from tkinter import *

# this is the function called when the button is clicked
def btnClickFunction():
    print('Submitted information to script.')


# this is a function to get the user input from the text input box
def getInputBoxValue():
    like_userInput = like_input.get()
    return like_userInput


# this is a function to get the user input from the text input box
def getInputBoxValue():
    comment_userInput = comment_input.get()
    return comment_userInput


# this is a function to get the user input from the text input box
def getInputBoxValue():
    follow_userInput = follow_input.get()
    return follow_userInput



root = Tk()

# This is the section of code which creates the main window
root.geometry('652x414')
root.configure(background='#00F5FF')
root.title('InstaBot')


# This is the section of code which creates a button
Button(root, text='Submit', bg='#F702D9', font=('arial', 12, 'normal'), 
command=btnClickFunction).place(x=280, y=287)

Label(root, text='Powered by Zephyr', bg='#00F5FF', foreground='#F702D9', font=('arial', 20, 
'bold')).place(x=190, y=10)


# This is the section of code which creates the a label
Label(root, text='Number of Likes', bg='#00F5FF', font=('arial', 12, 'bold')).place(x=125, y=110)


# This is the section of code which creates the a label
Label(root, text='% of Comments', bg='#00F5FF', font=('arial', 12, 'bold')).place(x=128, y=130)


# This is the section of code which creates the a label
Label(root, text='% of Follows', bg='#00F5FF', font=('arial', 12, 'bold')).place(x=138, y=150)


# This is the section of code which creates a text input box
like_input=Entry(root)
like_input.place(x=350, y=115)


# This is the section of code which creates a text input box
comment_input=Entry(root)
comment_input.place(x=350, y=135)


# This is the section of code which creates a text input box
follow_input=Entry(root)
follow_input.place(x=350, y=155)


root.mainloop()

您已為所有獲取輸入函數 (getInputBoxValue) 指定了相同的名稱。 您需要將它們中的每一個更改為唯一的,否則 python 每次只會執行最后一個函數定義。

# this is a function to get the user input from the text input box
def getInputBoxValue():
    like_userInput = like_input.get()
    return like_userInput


# this is a function to get the user input from the text input box
def getInputBoxValue():
    comment_userInput = comment_input.get()
    return comment_userInput


# this is a function to get the user input from the text input box
def getInputBoxValue():
    follow_userInput = follow_input.get()
    return follow_userInput

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM