我无法弄清楚为什么我的Entry()没有出现在我的程序窗口中。我环顾了互联网,无法弄清楚我做错了什么。
我正在尝试将我的Entry()字段放在程序中提交的主文本之上,但此时我会满意它在程序中显示出来。
除了我想要添加的EntryWidget之外,代码工作正常。
from tkinter import *
from tkinter.ttk import *
import subprocess as sub
import tkinter.messagebox
#use the doNothing function as a holder for anything that needs to call a function you have not made yet
def doNothing():
print("Do lots of nothing?")
#~~~~~~~~~~~< Message Box >~~~~~~~~~~~
def ihnb():
tkinter.messagebox.showinfo("This is an example!", "Icecream Has No Bones!")
answer = tkinter.messagebox.askquestion("This is not a real question", "Are you trying to become a programer?")
if answer == "yes":
a1 = "Then be prepared to spend countless hours hating life!"
root.text.insert(tkinter.END, a1)
root.text.see(tkinter.END)
else:
a2= "Smart move. Now go away!"
root.text.insert(tkinter.END, a2)
root.text.see(tkinter.END)
#create the window
root = Tk()
#modify root window
root.title("MINT: Mobile Information & Note-taking Tool")
root.geometry("800x600")
root.config(bg = 'Orange')
#~~~~~~~~~~~< Entry Widget >~~~~~~~~~~~
keywordEntry = Entry(root)
keywordEntry.grid(row=3, column=1)
keywordEntry.delete(0, END)
keywordEntry.insert(END, 'default text')
#~~~~~~~~~~~< Menu >~~~~~~~~~~~
menu = Menu(root)
root.config(menu=menu)
fileMenu = Menu(menu)
menu.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="Save", command=doNothing)
fileMenu.add_command(label="Save As", command=doNothing)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command= doNothing)
helpMenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpMenu)
helpMenu.add_command(label="Info", command=doNothing)
#~~~~~~~~~~~< Toolbar >~~~~~~~~~~~
spacer10 = " "
toolbar = Frame(root)
somethingButt = tkinter.Button(toolbar, fg = 'Black', bg = 'Orange', text = "Do Python?", command = ihnb)
somethingButt.grid(row = 0, column = 0, padx = 1, pady = 1, sticky = W)
buttonSpacer0_1 = tkinter.Button(toolbar, fg = 'Black', bg = 'Black', text = spacer10)
buttonSpacer0_1.grid(row = 0, column = 1, padx = 1, pady = 1, sticky = W)
somethingButt2 = tkinter.Button(toolbar, fg = 'White', bg = 'Black', text = "Do something?", command = doNothing)
somethingButt2.grid(row = 0, column = 2, padx = 1, pady = 1, sticky = W)
buttonSpacer0_1 = tkinter.Button(toolbar, fg = 'Black', bg = 'Black', text = spacer10)
buttonSpacer0_1.grid(row = 0, column = 3, padx = 1, pady = 1, sticky = W)
somethingButt3 = tkinter.Button(toolbar, fg = 'White', bg = 'Black', text = "Do something?", command = doNothing)
somethingButt3.grid(row = 0, column = 4, padx = 1, pady = 1, sticky = W)
toolbar.grid(row = 0, sticky = W)
#~~~~~~~~~~~< Toolbar >~~~~~~~~~~~
root.text = Text (root, width = 100, height = 10, fg='White', bg='Black', wrap = WORD)
root.text.grid(row = 10, padx=5, pady=5)
#~~~~~~~~~~~< Status Bar >~~~~~~~~~~~
status = Label(root, text = "Preparing to do nothing...", relief = SUNKEN, anchor = W)
status.grid(padx=5, pady=5, sticky = W)
root.mainloop()