【问题标题】:Tkinter - display buttonsTkinter - 显示按钮
【发布时间】:2020-12-14 07:46:22
【问题描述】:

我想使用 Tkinter 创建 3 个按钮并显示列表,其中包含列表文件、下载、上传和刷新功能。

只有列表文件有效,我运行时没有显示 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

【问题讨论】:

  • 这能回答你的问题吗? Python Tkinter button not appearing?
  • 你确定这是 google drive api 问题吗?它也可能是 tkinter 问题。在没有 tkinter 的情况下尝试这些功能(只需从 python 代码中调用它们,看看它是否有效)。此外,我建议使用调试工具,它有助于更​​轻松地发现错误
  • 要找到问题,我也需要谷歌驱动器的代码。
  • @ArmenSanoyan paste.ubuntu.com/p/Mkh8XsJshM 这是来自 quickstart.py
  • @DaImTo 我猜这不是 tkinter 问题

标签: python tkinter google-drive-api


【解决方案1】:

问题出在这里

listBox1 = 列表框(lb2,width=50,height=50,xscrollcommand=True)

列表框占用了太多空间。尝试降低高度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-24
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多