Python自定义在顶部插入白色条

fumotvh3  于 2022-12-24  发布在  Python
关注(0)|答案(2)|浏览(111)

我正在尝试为我的程序做一个图形用户界面。它基本上使用Steam Web API来获取给定游戏的数据。
我几乎完成了GUI,但是我在程序的顶部看到了一个白色的栏。我看过其他的帖子,但是似乎没有人有这个问题。
有什么办法修吗?
我知道代码很混乱,所以我已经道歉了。

import requests
import customtkinter
from tkinter import *
import tkinter.messagebox
import time
import math

customtkinter.set_appearance_mode("Dark")
customtkinter.set_default_color_theme("blue")

dpiError = False
try:
  from ctypes import windll
  windll.shcore.SetProcessDpiAwareness(1)
except:
  print('ERROR. Could not set DPI awareness.')
  dpiError = True

def runEvent1(arg):
    pass

class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()

        self.title('Steam DLC App')

        if dpiError:
            dpi = 96
        else:
            dpi = self.winfo_fpixels('1i')

        self.geometry(f'{math.ceil(1100 * dpi / 96)}x{math.ceil(660 * dpi / 96)}')
        self.grid_propagate(False)
        for x in range(60):
            Grid.columnconfigure(self, x, weight=1, uniform='row')
            Label(self, width=1).grid(row=0, column=x, sticky=N + S + E + W)
        for y in range(60):
            Grid.rowconfigure(self, y, weight=1, uniform='row')

        self.resizable(False, False)

        gameselected = customtkinter.CTkLabel(self, text="Game Selected:", font=('Helvetica', 14), width=1, height=1)
        gameselected.grid(row=21, column=2, columnspan=20, rowspan=2, sticky=W)

        appid_label = customtkinter.CTkLabel(self, text="AppID:", font=('Helvetica', 14), width=1, height=1)
        appid_label.grid(row=23, column=2, columnspan=20, rowspan=2, sticky=W)

        selected_games_dlcs = customtkinter.CTkLabel(self, text="Selected Games/DLCs", font=('Calibri', 14), width=1, height=1)
        selected_games_dlcs.grid(row=27, column=3, columnspan=53, rowspan=2, sticky=N + S + E + W)

        serial_number = customtkinter.CTkLabel(self, text="#", font=('Calibri', 14), width=1, height=1, bg_color="#2c2e30")
        serial_number.grid(row=31, column=3, columnspan=5, rowspan=2, sticky=N + S + E + W)

        gamedlc_title = customtkinter.CTkLabel(self, text="Game/DLC Title", font=('Calibri', 14), width=1, height=1,bg_color="#2c2e30")
        gamedlc_title.grid(row=31, column=8, columnspan=36, rowspan=2, sticky=N + S + E + W)

        appid_title = customtkinter.CTkLabel(self, text="AppID", font=('Calibri', 14), width=1, height=1,bg_color="#2c2e30")
        appid_title.grid(row=31, column=44, columnspan=12, rowspan=2, sticky=N + S + E + W)

        game_search = customtkinter.CTkLabel(self, text="Game Search", font=('Calibri', 14), width=1, height=1)
        game_search.grid(row=2, column=1, columnspan=24, rowspan=2, sticky=N + S + E + W)

        dlc_search_txt = customtkinter.CTkLabel(self, text="DLC Search", font=('Calibri', 14), width=1, height=1)
        dlc_search_txt.grid(row=2, column=36, columnspan=20, rowspan=2, sticky=N + S + E + W)

        Game_Search = customtkinter.CTkEntry(self, width=1, font=('Helvetica', 12), justify='center')
        Game_Search.grid(row=5, column=2, columnspan=20, rowspan=2, sticky=N + S + E + W)

        DLC_Search = customtkinter.CTkEntry(self, width=1, font=('Helvetica', 12), justify='center')
        DLC_Search.grid(row=5, column=36, columnspan=17, rowspan=2, sticky=N + S + E + W)

        Game_Search.insert(0, "Input Name/AppID")
        DLC_Search.insert(0, "Input Name/AppID")

        search_button = customtkinter.CTkButton(self, text="Go", font=('Arial', 12), width=1, height=1, command=lambda: runEvent1("search_button"), fg_color="#2b0658")
        search_button.grid(row=5, column=23, columnspan=2, rowspan=2, sticky=N + S + E + W)

        go_button = customtkinter.CTkButton(self, text="Go", font=('Arial', 12), width=1, height=1, command=lambda: runEvent1("Button1"), fg_color="#2b0658")
        go_button.grid(row=5, column=54, columnspan=2, rowspan=2, sticky=N + S + E + W)

        add_selected_dlc = customtkinter.CTkButton(self, text="Add Selected DLC(s)", font=('Helvetica', 12), width=1, height=1, command=lambda: runEvent1("add_selected_dlc"), fg_color="#2b0658")
        add_selected_dlc.grid(row=21, column=36, columnspan=8, rowspan=3, sticky=N + S + E + W)

        add_all_dlc = customtkinter.CTkButton(self, text="Add All DLC(s)", font=('Helvetica', 12), width=1, height=1, command=lambda: runEvent1("add_all_dlc"), fg_color="#2b0658")
        add_all_dlc.grid(row=21, column=48, columnspan=8, rowspan=3, sticky=N + S + E + W)

        set_applist_location = customtkinter.CTkButton(self, text="Set Applist Location", font=('Helvetica', 12), width=1, height=1, command=lambda: runEvent1("set_applist_location"), fg_color="#2b0658")
        set_applist_location.grid(row=53, column=3, columnspan=9, rowspan=3, sticky=N + S + E + W)

        save_changes = customtkinter.CTkButton(self, text="Save Changes", font=('Helvetica', 12), width=1, height=1, command=lambda: runEvent1("save_changes"), fg_color="#2b0658")
        save_changes.grid(row=53, column=46, columnspan=10, rowspan=3, sticky=N + S + E + W)

        remove_selected = customtkinter.CTkButton(self, text="Remove Selected", font=('Helvetica', 12), width=1, height=1, command=lambda: runEvent1("remove_selected"), fg_color="#2b0658")
        remove_selected.grid(row=53, column=20, columnspan=8, rowspan=3, sticky=N + S + E + W)

        clear_list = customtkinter.CTkButton(self, text="Clear List", font=('Helvetica', 12), width=1, height=1, command=lambda: runEvent1("clear_list"), fg_color="#2b0658")
        clear_list.grid(row=53, column=29, columnspan=8, rowspan=3, sticky=N + S + E + W)

        Add_Game = customtkinter.CTkButton(self, text="Add", font=('Arial', 12), width=1, height=1, command=lambda: runEvent1("Add_Game"), fg_color="#2b0658")
        Add_Game.grid(row=21, column=22, columnspan=3, rowspan=4, sticky=N + S + E + W)

        search_results = customtkinter.CTkFrame(self, width=1, height=1, fg_color="#2c2e30", border_color="#494d50", border_width=2)
        search_results.grid(row=9, column=2, columnspan=23, rowspan=11, sticky=N + S + E + W)

        dlc_search_frame = customtkinter.CTkFrame(self, width=1, height=1, fg_color="#2c2e30", border_color="#494d50", border_width=2)
        dlc_search_frame.grid(row=9, column=36, columnspan=20, rowspan=11, sticky=N + S + E + W)

        selected_games_dlcs_frame = customtkinter.CTkFrame(self, width=1, height=1, fg_color="#2c2e30", border_color="#494d50", border_width=2)
        selected_games_dlcs_frame.grid(row=33, column=3, columnspan=53, rowspan=19, sticky=N + S + E + W)


if __name__ == "__main__":
    app = App()
    app.mainloop()
o7jaxewo

o7jaxewo1#

顶部的白色条是您要添加到第0行的一组空标签,您似乎不需要它们,因此建议删除它们。您可以保留对columnconfigure的调用,或者删除该循环,并将其替换为对columnconfigure的单个调用,在该调用中,您将所有列号作为单个参数传递:

self.columnconfigure(tuple(range(60)), weight=1, uniform='row')
xzlaal3s

xzlaal3s2#

下面是一个视频,解释如何做到这一点:
https://www.youtube.com/watch?v=s0cpxPSN4k4
这是StackOverflow上的一个代码示例:
Can I change the title bar in Tkinter?
该函数被覆盖redirect():
然后你需要从头开始做一个标题栏。
我会提供一个代码的解决方案,但我不知道你到底在寻找什么。如果你添加一个图像或你正在寻找的描述,我也许可以帮助。

相关问题