Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望能够增加滚动条Scrollbar #7

Open
Accelerator086 opened this issue Jul 7, 2023 · 10 comments
Open

希望能够增加滚动条Scrollbar #7

Accelerator086 opened this issue Jul 7, 2023 · 10 comments

Comments

@Accelerator086
Copy link

有些漫画因为数目比较多,一个屏幕不能放下,看不到download的按钮,希望能够增加滚动条。

水平有限,大致思路是在main.py里放tk.Scrollbar()函数,但具体放在哪里、放什么参数,一直都没有尝试成功。

image

@54Jezz
Copy link

54Jezz commented Jul 14, 2023

确实

@Jay921027
Copy link

確實需要

@seacatwu
Copy link
Contributor

我之前改的时候也不会,所以,加了一列。。。。

@l1nzh11
Copy link

l1nzh11 commented Mar 7, 2024

我一开始懒得改直接竖屏显示,笑死

@seacatwu
Copy link
Contributor

我用gpt加了滚动条,打包以后程序文件超过25m,无法上传了。main.py如下

# @Author: Xiangxin Kong
# @Date: 2020.5.30
import tkinter as tk
from tkinter import *
from tkinter import Canvas
from downloader import *

class mainWindow(tk.Tk):
    def __init__(self):
        super().__init__()
        super().title('Manhuagui Downloader')
        super().geometry('400x160')
        baseY = 30
        tk.Label(self, text='Url:', font=('Arial', 16,)).place(x=10, y=baseY)
        tk.Label(self, text='To:', font=('Arial', 16,)).place(x=10, y=baseY + 40)
        self.var_address = tk.StringVar()
        self.var_url = tk.StringVar()
        self.var_address.set('manga/')
        self.var_url.set('https://www.manhuagui.com/comic/24973/')
        tk.Entry(self, textvariable=self.var_url, font=('Arial', 14), width=28).place(x=60, y=baseY)
        tk.Entry(self, textvariable=self.var_address, font=('Arial', 14), width=28).place(x=60, y=baseY + 40)
        tk.Button(self, text='Download', font=('Arial', 12), command=self.download).place(x=290, y=baseY + 80)
        self.mainloop()

    def download(self):
        try:
            s = MangaDownloader(self.var_url.get(), self.var_address.get())
        except:
            print("Manga not Found")
            self.var_url.set("")
            return
        downloadPanel(s)

class downloadPanel(Toplevel):
    def __init__(self, s):
        super().__init__()
        super().title('Manhuagui Downloader')

        super().geometry('1600x600')

        # 创建滚动条
        self.scrollbar = Scrollbar(self)
        self.scrollbar.pack(side=RIGHT, fill=Y)

        # 创建Canvas,并关联滚动条
        self.canvas = Canvas(self, yscrollcommand=self.scrollbar.set)
        self.canvas.pack(side='left', fill='both', expand=True)

        self.scroll_frame = Frame(self.canvas)
        self.canvas.create_window(0, 0, window=self.scroll_frame, anchor='nw')
 
        # 设置滚动条的命令为移动Canvas
        self.scrollbar.config(command=self.canvas.yview)

        self.scroll_frame.bind('<Configure>', self.set_scroll_region)
        self.canvas.bind_all("<MouseWheel>", self._on_mousewheel)
        self.place_label(s)
        self.place_buttons(s)

        var = IntVar()

        def checkAll():
            for i in self.buttons:
                if var.get() == 1:
                    i.select()
                elif i.cget("state") == 'normal':
                    i.deselect()

        tk.Checkbutton(self.scroll_frame, text='Select All', font=('Arial', 18), variable=var, command=checkAll).grid(row=2, column=0, sticky=W)

        tk.Button(self.scroll_frame, text='Download', font=('Arial', 16), command=lambda: self.downloadChapters(s)).grid(row=2, column=1, sticky=W)

        self.mainloop()
        


    def place_buttons(self, s):
        self.buttons = []
        ROW_OFFSET = 3 # 偏移量
        for i in range(len(s.chapters)):
            s.chapters[i][2] = IntVar()
            cha = tk.Checkbutton(self.scroll_frame, text=s.chapters[i][0], font=('Arial', 14), variable=s.chapters[i][2])
            cha.grid(row=i // 5 + ROW_OFFSET, column=i % 5,sticky=W)
            if s.chapters[i][0] in s.existedChapters():
                cha.select()
                cha.config(state='disabled')
            self.buttons.append(cha)
        self.baseY += (s.length // 5) * 40    

    def set_scroll_region(self, event):
        self.canvas.configure(scrollregion=self.canvas.bbox('all'))

    def place_label(self, s):
        tk.Label(self.scroll_frame, text=s.title, font=('Arial', 33,)).grid(row=0, column=0, sticky=W)
        tk.Label(self.scroll_frame, text="作者: " + s.author, font=('Arial', 12,)).grid(row=1, column=0, sticky=W)
        tk.Label(self.scroll_frame, text="年代: " + s.year, font=('Arial', 12,)).grid(row=1, column=1, sticky=W)
        tk.Label(self.scroll_frame, text="地区: " + s.region, font=('Arial', 12,)).grid(row=1, column=2, sticky=W)
        tk.Label(self.scroll_frame, text="类型: " + s.plot, font=('Arial', 12,)).grid(row=1, column=3, sticky=W)
        self.baseY = 120
        self.canvas.update_idletasks()

    def downloadChapters(self, s):
        for i in range(s.length):
            if self.buttons[i].cget("state") == 'normal' and s.chapters[i][2].get():
                s.downloadChapter(s.chapters[i][1])
    def _on_mousewheel(self, event):
        self.canvas.yview_scroll(int(-1*(event.delta/120)), "units")


if __name__ == '__main__':
    mainWindow()

@seacatwu
Copy link
Contributor

image

@seacatwu
Copy link
Contributor

有滚动条的打包程序超过25M,我没法上传了

@SugaryStudent
Copy link

有滚动条的打包程序超过25M,我没法上传了

可以放一个网盘链接分享

@panbrt
Copy link

panbrt commented May 15, 2024

请问可以上传给我吗?

@seacatwu
Copy link
Contributor

seacatwu commented Jun 2, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants