我在HTMLQuestion表单中使用javascript代码来验证用户输入。
from tkinter import *
import os, shelve
food_entry = None
# Opens a new window for entering food items
def data_window():
global food_entry
new_window_entry = Toplevel() # Change to Toplevel (a popup) instead of a new Tk instance
new_window_entry.title('Data Entry Window')
Label(new_window_entry, text = 'Enter the food items you have eaten below, separated by commas:').grid(sticky = W, columnspan = 2)
Label(new_window_entry, text = '(i.e. Apple, Eggs, Ground Beef)').grid(sticky = W, columnspan = 2)
food_entry = Text(new_window_entry, width = 55, height = 2, wrap = WORD)
food_entry.grid(sticky = W, columnspan = 2)
Label(new_window_entry, text = 'Within two hours after eating, did you experience any of the following symptoms:').grid(sticky = W, columnspan = 2)
Label(new_window_entry, justify = LEFT, wraplength = 450, text = 'bloating, diarrhea, nausea, vomiting, irritable bowel, skin rashes, fatigue, joint pain, dark circles under the eyes, night sweats, or tingling or swelling of the face, fingers, feet or other extemities?').grid(sticky = W, columnspan = 2)
Radiobutton(new_window_entry, text = 'Yes', variable = inflam, value = 'y').grid(row = 9, column = 0, sticky = E)
Radiobutton(new_window_entry, text = 'No', variable = inflam, value = 'n').grid(row = 9, column = 1, sticky = W)
Button(new_window_entry, text = 'Submit', command = check_data).grid(row = 10, column = 0, sticky = W + E)
Button(new_window_entry, text = 'Cancel', command = new_window_entry.destroy).grid(row = 10, column = 1, sticky = W + E)
#new_window_entry.mainloop() No need for this, the mainloop is already running
def check_data():
global food_entry
print(food_entry.get(1.0, END))
if food_entry.get(1.0, END).strip() == '':
print('Nothing Entered')
else:
print('Next Function')
root = Tk()
inflam = StringVar() # move inflam init to a broader scope so that the buttons don't but
inflam.set('n') # initialize it as 'n'
root.title('')
Label(root, text = 'Food Tracker v3.0').grid(columnspan = 2)
Button(root, text = 'Enter Data', command = data_window).grid(row = 1, column = 0, sticky = W)
#Button(root, text = 'View Data', command = view_window).grid(row = 1, column = 1, sticky = E)
root.mainloop()
遗憾的是我没有得到javascript代码。我试图跟踪html代码,结果发现每个匹配将被阻止为IFrame。它看起来像亚马逊机械土耳其人不允许嵌入javascript代码