我想在表单未填写时添加错误页面 python tkinter
I want to add error page when form is not filled in python tkinter
首先给大家介绍一下项目
from tkinter import *
import os
window = Tk()
window.title("Social Searcher")
window.wm_attributes('-toolwindow', 'True')
Tk_Width = 350
Tk_Height = 150
positionRight = int( window.winfo_screenwidth()/2 - Tk_Width/2 )
positionDown = int( window.winfo_screenheight()/2 - Tk_Height/2 )
window.geometry("{}x{}+{}+{}".format(330,100,positionRight, positionDown))
stxt = Label(window, text = "username").place(x = 30, y = 10)
s = Entry(window, width=30)
s.insert(0,"")
s.grid(row=1, column=0, padx=100, pady=10)
def Message():
os.system(f"If Not Exist \"History.txt\" (echo Social Searcher history)>\"History.txt\"")
os.system(f"If Exist \"History.txt\" (echo {s.get()})>>\"History.txt\"")
os.system(f"start https://www.facebook.com/{s.get()}")
os.system(f"start https://www.instagram.com/{s.get()}")
os.system(f"start https://www.tiktok.com/@{s.get()}")
os.system(f"start https://twitter.com/{s.get()}")
os.system(f"start https://story.snapchat.com/@{s.get()}")
btnSendMessage = Button(window, text="Search", width=20, command=Message)
btnSendMessage.grid(row=5, column=0, padx=10, pady=10)
window.mainloop()
目前,如果我不在(用户名)字段中输入任何内容,代码将起作用。
如果我没有输入任何内容,我想显示一个错误页面。
我试着把这段代码放在这里
def Message():
os.system("if ( {s.get()} -eq ""){exit}")
os.system(f"If Not Exist \"History.txt\" (echo Social Searcher history)>\"History.txt\"")
os.system(f"If Exist \"History.txt\" (echo {s.get()})>>\"History.txt\"")
os.system(f"start https://www.facebook.com/{s.get()}")
os.system(f"start https://www.instagram.com/{s.get()}")
os.system(f"start https://www.tiktok.com/@{s.get()}")
os.system(f"start https://twitter.com/{s.get()}")
os.system(f"start https://story.snapchat.com/@{s.get()}")
但是没用
@Matiiss 的回答
from tkinter import *
import os
window = Tk()
window.title("Social Searcher")
window.wm_attributes('-toolwindow', 'True')
Tk_Width = 350
Tk_Height = 150
positionRight = int( window.winfo_screenwidth()/2 - Tk_Width/2 )
positionDown = int( window.winfo_screenheight()/2 - Tk_Height/2 )
window.geometry("{}x{}+{}+{}".format(330,100,positionRight, positionDown))
stxt = Label(window, text = "username").place(x = 30, y = 10)
s = Entry(window, width=30)
s.insert(0,"")
s.grid(row=1, column=0, padx=100, pady=10)
def Message():
if not s.get(): return
os.system(f"If Not Exist \"History.txt\" (echo Social Searcher history)>\"History.txt\"")
os.system(f"If Exist \"History.txt\" (echo {s.get()})>>\"History.txt\"")
os.system(f"start https://www.facebook.com/{s.get()}")
os.system(f"start https://www.instagram.com/{s.get()}")
os.system(f"start https://www.tiktok.com/@{s.get()}")
os.system(f"start https://twitter.com/{s.get()}")
os.system(f"start https://story.snapchat.com/@{s.get()}")
btnSendMessage = Button(window, text="Search", width=20, command=Message)
btnSendMessage.grid(row=5, column=0, padx=10, pady=10)
window.mainloop()
首先给大家介绍一下项目
from tkinter import *
import os
window = Tk()
window.title("Social Searcher")
window.wm_attributes('-toolwindow', 'True')
Tk_Width = 350
Tk_Height = 150
positionRight = int( window.winfo_screenwidth()/2 - Tk_Width/2 )
positionDown = int( window.winfo_screenheight()/2 - Tk_Height/2 )
window.geometry("{}x{}+{}+{}".format(330,100,positionRight, positionDown))
stxt = Label(window, text = "username").place(x = 30, y = 10)
s = Entry(window, width=30)
s.insert(0,"")
s.grid(row=1, column=0, padx=100, pady=10)
def Message():
os.system(f"If Not Exist \"History.txt\" (echo Social Searcher history)>\"History.txt\"")
os.system(f"If Exist \"History.txt\" (echo {s.get()})>>\"History.txt\"")
os.system(f"start https://www.facebook.com/{s.get()}")
os.system(f"start https://www.instagram.com/{s.get()}")
os.system(f"start https://www.tiktok.com/@{s.get()}")
os.system(f"start https://twitter.com/{s.get()}")
os.system(f"start https://story.snapchat.com/@{s.get()}")
btnSendMessage = Button(window, text="Search", width=20, command=Message)
btnSendMessage.grid(row=5, column=0, padx=10, pady=10)
window.mainloop()
目前,如果我不在(用户名)字段中输入任何内容,代码将起作用。
如果我没有输入任何内容,我想显示一个错误页面。
我试着把这段代码放在这里
def Message():
os.system("if ( {s.get()} -eq ""){exit}")
os.system(f"If Not Exist \"History.txt\" (echo Social Searcher history)>\"History.txt\"")
os.system(f"If Exist \"History.txt\" (echo {s.get()})>>\"History.txt\"")
os.system(f"start https://www.facebook.com/{s.get()}")
os.system(f"start https://www.instagram.com/{s.get()}")
os.system(f"start https://www.tiktok.com/@{s.get()}")
os.system(f"start https://twitter.com/{s.get()}")
os.system(f"start https://story.snapchat.com/@{s.get()}")
但是没用
@Matiiss 的回答
from tkinter import *
import os
window = Tk()
window.title("Social Searcher")
window.wm_attributes('-toolwindow', 'True')
Tk_Width = 350
Tk_Height = 150
positionRight = int( window.winfo_screenwidth()/2 - Tk_Width/2 )
positionDown = int( window.winfo_screenheight()/2 - Tk_Height/2 )
window.geometry("{}x{}+{}+{}".format(330,100,positionRight, positionDown))
stxt = Label(window, text = "username").place(x = 30, y = 10)
s = Entry(window, width=30)
s.insert(0,"")
s.grid(row=1, column=0, padx=100, pady=10)
def Message():
if not s.get(): return
os.system(f"If Not Exist \"History.txt\" (echo Social Searcher history)>\"History.txt\"")
os.system(f"If Exist \"History.txt\" (echo {s.get()})>>\"History.txt\"")
os.system(f"start https://www.facebook.com/{s.get()}")
os.system(f"start https://www.instagram.com/{s.get()}")
os.system(f"start https://www.tiktok.com/@{s.get()}")
os.system(f"start https://twitter.com/{s.get()}")
os.system(f"start https://story.snapchat.com/@{s.get()}")
btnSendMessage = Button(window, text="Search", width=20, command=Message)
btnSendMessage.grid(row=5, column=0, padx=10, pady=10)
window.mainloop()