更新:我修复了上一期,但现在我有了这个,我以前从未见过这个错误 TypeError:insert()缺少1个必需的位置参数:' chars' 如果有人能够解释这意味着什么会很棒,谢谢......这是我完成项目所需的最后一件事我做了其他一切:)$
更新:更改代码现在出现此错误: $ python random.py 文件" random.py",第78行 def消息(自我): ^ IndentationError:unindent与任何外部缩进级别都不匹配
#Imports the moduels needed
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk #EDIT: This module worked for me after I installed Pillow in my computer from "http://pillow.readthedocs.io/en/4.1.x/installation.html"
import webbrowser #imports the module for URL links
import io, base64 #imports the module for letting images be seen without changing code
#adds the URL and window for the program tkinter
URL = "http://windowhut.com.au" #the URL used
window = tk.Tk() #this makes the tkinter window appear
window.title("window App") #title of the app
window.geometry("500x500") #size of the app
#define IntVar variables
cvar = tk.IntVar()
cvar2 = tk.IntVar()
cvar3 = tk.IntVar()
#defines the webbrowser function
def open_ph(event):
webbrowser.open_new_tab(URL)
#define the main button and the click button
button = tk.Button(window, text="Welcome to Awesome pizza")
button.grid(column=0, row=0)
button.bind("<Button-1>", open_ph)
#define check buttons
check1 = ttk.Checkbutton(window, text="Meat Lovers", variable=cvar, onvalue=1, offvalue=0)
check1.grid(column=0, row=1, padx=(5, 95))
check2 = ttk.Checkbutton(window, text="Supreme", variable=cvar2, onvalue=1, offvalue=0)
check2.grid(column=0, row=3, padx=(10, 120))
check3 = ttk.Checkbutton(window, text="Vegetarian", variable=cvar3, onvalue=1, offvalue=0)
check3.grid(column=0, row=5, padx=(10, 120))
#define the option menu
choice = tk.OptionMenu(window, tk.IntVar(), "Select your size!", "Small", "Medium", "Large")
choice.grid(column=1, row=0, padx=(5, 95))
#define labels
name_label = tk.Label(text="Name")
name_label.grid(column=1, row=1, padx=(10, 120))
number_label = tk.Label(text="Contact number")
number_label.grid(column=1, row=3, padx=(5, 95))
address_label = tk.Label(text="Delivery address")
address_label.grid(column=1, row=5, padx=(5, 95))
#define entries
name_entry = tk.Entry()
name_entry.grid(column=1, row=2, padx=(5, 95))
number_entry = tk.Entry()
number_entry.grid(column=1, row=4, padx=(5, 95))
address_entry = tk.Entry()
address_entry.grid(column=1, row=6, padx=(5, 95))
#defines the print function for the message board
def message_customer():
print(name_entry.get())
print(number_entry.get())
print(address_entry.get())
name = Person(name_entry.get(), number_entry.get(), address_entry.get())
print(name.message())
text_answer = tk.Text(master=window, height=10, width=20)
text_answer.grid(column=1, row=7, padx=(10, 120))
text_answer.insert("1.0", "Thank you {name} for ordering our window, it should be ready within 30 mintues!, have a great day!".format(name=name.name, message=name.message()))
#define click button function
click_button = tk.Button(text="Complete Order", command=message_customer)
click_button.grid(column=1, row=7, padx=(5, 95))
#create class method
class Person:
def __init__(self, name, number=None, address=None):
self.name = name
self.number = number
self.address = address
def message(self):
message = name.name + name.number + name.address - 1
return message
window.mainloop()#lets the window stay open, very important
答案 0 :(得分:1)
根据the docs,insert
方法需要2个位置(排序事项)参数。 e.g。
text.insert('1.0', 'here is my text to insert')
您只提供了第二个参数,添加第一个参数(&#34;在哪里插入&#34;)。