Tkinter - 显示按钮
Tkinter - display buttons
我想使用具有列表文件、下载、上传和刷新功能的 Tkinter 创建 3 个按钮和显示列表。
只有 listfile 有效,我 运行 时没有显示 3 个按钮。是我做错了什么还是漏掉了一些步骤?
这是我的代码:
main.py
from __future__ import print_function
from tkinter import *
from tkinter import filedialog
import tkinter.messagebox
from quickstart import *
root = Tk()
root.title("Hello")
def Upload():
try:
path = filedialog.askopenfile()
FilePath=path.name
Uploadfile(FilePath)
except(AttributeError):
tkinter.messagebox.showerror("wanring" ,"No file choice!!!")
def DownLoad():
indexs = listBox1.curselection()
for i in indexs:
Downloadfile(i,listBox1.get(i))
def Refresh():
listBox1.delete(0,END)
items = listfile()
for item in items:
listBox1.insert(items.index(item),str(items.index(item))+") "+item['name'])
listBox1.pack()
lb1=Label(root,text="Connect with driver!!",font=("Times New Roman",14),fg="red")
lb1.pack(side = TOP)
# list name and index of items
lb2=Label(root)
lb2.pack(side = BOTTOM)
####
items = listfile()
listBox1 = Listbox(lb2,width=50,height=50,xscrollcommand=True)
for item in items:
listBox1.insert(items.index(item),str(items.index(item))+") "+item['name'])
listBox1.pack()
#3 button
pnw1=PanedWindow(lb2,orient=HORIZONTAL)
pnw1.pack()
btnSelect=tkinter.Button(pnw1,text=("Upload"),command=Upload,bg='blue',fg='red')
pnw1.add(btnSelect)
btnDow=tkinter.Button(pnw1,text=("Download"),command=DownLoad,bg='blue',fg='red')
pnw1.add(btnDow)
btnDow=tkinter.Button(pnw1,text=("Refresh"),command=Refresh,bg='blue',fg='red')
pnw1.add(btnDow)
root.mainloop()
您可以找到 quickstart
文件 here
问题出在这里
listBox1 = Listbox(lb2,width=50,height=50,xscrollcommand=True)
列表框占用太多空间。尽量降低高度。
我想使用具有列表文件、下载、上传和刷新功能的 Tkinter 创建 3 个按钮和显示列表。
只有 listfile 有效,我 运行 时没有显示 3 个按钮。是我做错了什么还是漏掉了一些步骤?
这是我的代码:
main.py
from __future__ import print_function
from tkinter import *
from tkinter import filedialog
import tkinter.messagebox
from quickstart import *
root = Tk()
root.title("Hello")
def Upload():
try:
path = filedialog.askopenfile()
FilePath=path.name
Uploadfile(FilePath)
except(AttributeError):
tkinter.messagebox.showerror("wanring" ,"No file choice!!!")
def DownLoad():
indexs = listBox1.curselection()
for i in indexs:
Downloadfile(i,listBox1.get(i))
def Refresh():
listBox1.delete(0,END)
items = listfile()
for item in items:
listBox1.insert(items.index(item),str(items.index(item))+") "+item['name'])
listBox1.pack()
lb1=Label(root,text="Connect with driver!!",font=("Times New Roman",14),fg="red")
lb1.pack(side = TOP)
# list name and index of items
lb2=Label(root)
lb2.pack(side = BOTTOM)
####
items = listfile()
listBox1 = Listbox(lb2,width=50,height=50,xscrollcommand=True)
for item in items:
listBox1.insert(items.index(item),str(items.index(item))+") "+item['name'])
listBox1.pack()
#3 button
pnw1=PanedWindow(lb2,orient=HORIZONTAL)
pnw1.pack()
btnSelect=tkinter.Button(pnw1,text=("Upload"),command=Upload,bg='blue',fg='red')
pnw1.add(btnSelect)
btnDow=tkinter.Button(pnw1,text=("Download"),command=DownLoad,bg='blue',fg='red')
pnw1.add(btnDow)
btnDow=tkinter.Button(pnw1,text=("Refresh"),command=Refresh,bg='blue',fg='red')
pnw1.add(btnDow)
root.mainloop()
您可以找到 quickstart
文件 here
问题出在这里
listBox1 = Listbox(lb2,width=50,height=50,xscrollcommand=True)
列表框占用太多空间。尽量降低高度。