我想從我的Leo.py
文件導入變量我Max.py
文件是這樣的:Leo.py:與進口從python腳本變量python腳本問題
> import tkinter import time import os import Max from tkinter import *
> from tkinter import messagebox as tkMessageBox from selenium import
> webdriver from selenium.webdriver.common.by import By 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.action_chains import ActionChains from time
> import sleep from selenium.webdriver.support.ui import WebDriverWait
>
>
> def combined_func(*args, **kwargs):
> for f in funcs:
> f(*args, **kwargs)
> return combined_func
>
> def Name():
> global Name
> Name = t.get()
>
> def Message():
> global Message
> Message = t2.get()
>
> def Number():
> global Number
> Number_string = t3.get()
> Number = int(Number_string)
>
> def Delay():
> global Delay
> Delay_string= t4.get()
> Delay = int(Delay_string)
>
> def close_window():
> root.destroy()
>
> root = Tk()
>
> w = Label(width = '40', height = '0') w.pack()
>
> t = Entry(root) t.insert(INSERT, 'Insert Name') t.pack()
>
> t2 = Entry(root) t2.insert(INSERT, 'Insert Messsage') t2.pack()
>
> t3 = Entry(root) t3.insert(INSERT, 'Insert Number') t3.pack()
>
> t4 = Entry(root) t4.insert(INSERT, 'Insert Delay') t4.pack()
>
> b = Button(root, text='Run', command = combine_funcs(Name, Message,
> Number, Delay, close_window)) b.pack()
>
> mainloop()
>
> os.system('Max.py')
>
> browser = webdriver.Chrome() browser.get('https://web.whatsapp.com/')
> wait = browser.implicitly_wait(3)
>
> time.sleep(10)
>
> N=1 Spam = 1
>
> actions = ActionChains(browser) for _ in range(N):
> actions = actions.send_keys(Keys.TAB) actions.perform()
>
> for _ in range(N):
> actions = actions.send_keys(Name) actions.perform()
>
> time.sleep(2)
>
> for _ in range(N):
> actions = actions.send_keys(Keys.TAB) actions.perform()
>
> time.sleep(2)
>
> for _ in range(N):
> actions = actions.send_keys(Keys.ENTER) actions.perform()
>
> time.sleep(2)
>
> while (Spam <= Number):
>
> for _ in range (1):
> actions = actions.send_keys(Message, Keys.ENTER)
> actions.perform()
> Spam += 1
> actions.reset_actions()
> time.sleep(Delay)
Max.py:
> import Leo from Leo import * import tkinter from tkinter import *
>
> root = Tk()
>
> count = Label(root, text = Number)
>
> mainloop()
但始終運行Leo.py
紙條給我的錯誤
NameError: name 'Number' is not defined
如何使用Max.py
中Leo.py
的變量?
感謝提前任何幫助:)
請嘗試格式化你的代碼。 –
請原諒我亂碼。我對此很新。 :) – Leo