Когда я помещаю ввод из окна ввода в переменную и распечатываю его, ничего не появляется. Кто-нибудь может мне помочь? - PullRequest
0 голосов
/ 10 июля 2020

В настоящее время я работаю над сценарием, который отправляет сообщения через WhatsApp, когда вы пишете сообщение и имя (имена) группы или человека в окне ввода tkinter. На данный момент, когда дело доходит до отправки сообщения, сообщение или контакты не отображаются, поэтому я попытался распечатать переменные, но они не появились. Я пробовал менять переменные, но не уверен, что могу что-то сделать. У меня есть ощущение, что это могло быть связано с тем, что мне пришлось назначить переменные, которые содержат окно ввода, как переменную tk.string, потому что по какой-то причине я не мог назначить их как глобальные переменные. Вот мой код:

import tkinter
import tkinter as tk
import pyautogui
root = tk.Tk()
v = tk.IntVar()
message_var = tk.StringVar()
recipient_var_one = tk.StringVar()
recipient_var_two = tk.StringVar()
recipient_var_three = tk.StringVar()
recipient_var_four = tk.StringVar()
recipient_var_five = tk.StringVar()
message_entry = tk.StringVar()
recipient_entry_one = tk.StringVar()
recipient_entry_two = tk.StringVar()
recipient_entry_three = tk.StringVar()
recipient_entry_four = tk.StringVar()
recipient_entry_five = tk.StringVar()
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By



def message_send():
    message = message_var.get()
    recipients_one = recipient_var_one.get()
    recipients_two = recipient_var_two.get()
    recipients_three = recipient_var_three.get()
    recipients_four = recipient_var_four.get()
    recipients_five = recipient_var_five.get()
    message_var.set("")
    recipient_var_one.set("")
    recipient_var_two.set("")
    recipient_var_three.set("")
    recipient_var_four.set("")
    recipient_var_five.set("")


    driver = webdriver.Chrome('C:/Program Files(x86)/chromedriver_win32/chromedriver')

    driver.get("https://web.whatsapp.com/")
    wait = WebDriverWait(driver, 600)



    string = message
    x_arg = '//span[contains(@title,' + recipients_one + ')]'
    group_title = wait.until(EC.presence_of_element_located((
        By.XPATH, x_arg)))
    group_title.click()





#This function contains the code for the main message interface. This also contains the recipient variables.
def begin():
    import tkinter

    window = tkinter.Tk()
    window.title("Whatsapp Message Creator")
    tkinter.Label(window, text="Write advert here:").grid(row=0)
    message_entry = tkinter.Entry(window, textvariable = message_var).grid(row=0, column=1)# 'username' is placed on position 00 (row - 0 and column - 0)
    tkinter.Label(window, text="Write recipient 1 here:").grid(row=1)
    recipient_entry_one = tkinter.Entry(window, textvariable = recipient_var_one).grid(row=1, column=1)
    tkinter.Label(window, text="Write recipient 2 here:").grid(row=2)
    recipient_entry_two = tkinter.Entry(window, textvariable = recipient_var_two).grid(row=2, column=1)
    tkinter.Label(window, text="Write recipient 3 here:").grid(row=3)
    recipient_entry_three = tkinter.Entry(window, textvariable = recipient_var_three).grid(row=3, column=1)
    tkinter.Label(window, text="Write recipient 4 here:").grid(row=4)
    recipient_entry_four = tkinter.Entry(window, textvariable = recipient_var_four).grid(row=4, column=1)
    tkinter.Label(window, text="Write recipient 5 here:").grid(row=5)
    recipient_entry_five = tkinter.Entry(window, textvariable = recipient_var_five).grid(row=5, column=1)
    send_button = tk.Button(root, text='Send', width=20, command=message_send) #message_send function will contain all the programming to send the message.
    send_button.pack()
    tkinter.mainloop()
window = tk.Label(root,
        text="""Welcome to the Whatsapp Message Creator!""",
        justify = tk.LEFT,
        padx = 20).pack()

button = tk.Button(root, text='Begin', width=20, command=begin)
button.pack()
button = tk.Button(root, text='Exit', width=20, command=root.destroy)
button.pack()


root.mainloop()
tkinter.mainloop()
tkinter.mainloop()

Может ли кто-нибудь помочь мне найти проблему? Спасибо!

1 Ответ

0 голосов
/ 10 июля 2020

Как я уже говорил вам в предыдущем вопросе, вы должны определить виджет ввода в одной переменной, а затем расположить его в отдельной строке, например,

message_var = StringVar()
message_entry = Entry(window, textvariable = message_var)
message_entry.grid(row=0, column=1)

А позже вы можете просто сказать message_entry.get() или message_var.get(), и он вернет ввод, который вы ввели в виджете ввода

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...