首页 > 编程知识 正文

tkinter ,tkinter入门教程

时间:2023-05-05 19:23:56 阅读:259753 作者:2590

tkinter

tkinter 怎么做debug?

def insert_end(): var = e.get() t.insert('add', var)

File “D:torchenvlibtkinter_init_.py”, line 3738, in insert
self.tk.call((self._w, ‘insert’, index, chars) + args)
_tkinter.TclError: bad text index “add”

def insert_end(): var = e.get() t.insert('end', var) 2 Exception in Tkinter callbackTraceback (most recent call last): File "D:torchenvlibtkinter__init__.py", line 1883, in __call__ return self.func(*args) File "E:/Practice/python_work/Jupyter/Tkinter/tkinter_pycharm/selection_list.py", line 17, in print_selection value = lb.get(lb.curselection()) File "D:torchenvlibtkinter__init__.py", line 3182, in get return self.tk.call(self._w, 'get', first)_tkinter.TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number

这是因为没有选择任何一项

1 def usr_login(): usr_name = var_usr_name.get() usr_pwd = var_usr_pwd.get() try: with open('usrs_info.pickle', 'rb') as usr_file: usr_info = pickle.load(usr_file) except FileExistsError: #这里错了 with open('usrs_info.pickle', 'ab+') as usr_file: usr_info = {'admin', 'admin'} pickle.dump(usr_info, usr_file)

Exception in Tkinter callback Traceback (most recent call last): File "D:torchenvlibtkinter__init__.py", line 1883, in __call__ return self.func(*args) File "E:/Practice/python_work/Jupyter/Tkinter/tkinter_pycharm/No13_WelcomeWindow.py", line 36, in usr_login with open('usrs_info.pickle', 'rb') as usr_file: FileNotFoundError: [Errno 2] No such file or directory: 'usrs_info.pickle'
except处理的问题还是显示出来了,说明不对

def usr_login(): usr_name = var_usr_name.get() usr_pwd = var_usr_pwd.get() try: with open('usrs_info.pickle', 'rb') as usr_file: usr_info = pickle.load(usr_file) except FileNotFoundError: with open('usrs_info.pickle', 'ab+') as usr_file: usr_info = {'admin', 'admin'} pickle.dump(usr_info, usr_file) 2 except FileNotFoundError: with open('usrs_info.pickle', 'wb') as usr_file: usr_info = {'admin', 'admin'} pickle.dump(usr_info, usr_file) debug type(usr_info)<class 'set'>

Exception in Tkinter callback Traceback (most recent call last): File "D:torchenvlibtkinter__init__.py", line 1883, in __call__ return self.func(*args) File "E:/Practice/python_work/Jupyter/Tkinter/tkinter_pycharm/No13_WelcomeWindow.py", line 45, in usr_login if usr_pwd == usr_info[usr_name]: TypeError: 'set' object is not subscriptable

except FileNotFoundError: with open('usrs_info.pickle', 'wb') as usr_file: usr_info = {'admin': 'admin'} #逗号改为了冒号 pickle.dump(usr_info, usr_file) type(usr_file)<class '_io.BufferedRandom'>type(usr_info)<class 'dict'> 3 tkmsgbox.showinfo(title='Welcome', text='You are in circle')

Exception in Tkinter callback Traceback (most recent call last): File "D:torchenvlibtkinter__init__.py", line 1883, in __call__ return self.func(*args) File "E:/Practice/python_work/Jupyter/Tkinter/tkinter_pycharm/No13_WelcomeWindow.py", line 73, in sign_to_python tkmsgbox.showinfo(title='Welcome', text='You are in circle') File "D:torchenvlibtkintermessagebox.py", line 84, in showinfo return _show(title, message, INFO, OK, **options) File "D:torchenvlibtkintermessagebox.py", line 72, in _show res = Message(**options).show() File "D:torchenvlibtkintercommondialog.py", line 44, in show s = w.tk.call(self.command, *w._options(self.options)) _tkinter.TclError: bad option "-text": must be -default, -detail, -icon, -message, -parent, -title, or -type

tkmsgbox.showinfo(title='Welcome', message='You are in circle') 问题 tk 如何添加jpg?pickle文件?pickle? label_1 = tk.Label(window, bg='yellow', width=30, height=2, text='empty').pack()

Exception in Tkinter callback Traceback (most recent call last): File "D:torchenvlibtkinter__init__.py", line 1883, in __call__ return self.func(*args) File "E:/Practice/python_work/Jupyter/Tkinter/tkinter_pycharm/Radiobutton.py", line 14, in print_selection label_1.config(text='you have selected' + selected_var.get()) AttributeError: 'NoneType' object has no attribute 'config'

label_1 = tk.Label(window, bg='yellow', width=30, height=2, text='empty')label_1.pack() if (var1 == 1) & (var2 == 0): label_1.config(text='Only Python')

我是按照“安装”顺序从上到下写程序的

莫烦是按照结构 从上到下写程序的,写了结构以后,再回过头往结构里面填充内容

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。