Python3:无法获取Gtk.SpinButton值

时间:2019-06-26 10:40:26

标签: python python-3.x gtk3

我正在尝试在List<MyDO> processedList = new ArrayList<>(dataList.size()); for(int i = 0, num = dataList.size(); i < num; i++) { if(...) { // your filter criteria MyDO myDO = dataList.get(i); try { ...// some error at i } catch(Exception ex) { throw new IllegalStateException("at index "+i, ex); } processedList.add(myDO); } } 中创建一个程序。 但是,我不知道如何调用我的List<MyDO> processedList = new ArrayList<>(dataList.size()); for(int i = 0, num = dataList.size(); i < num; i++) { if(...) { // your filter criteria MyDO myDO = dataList.get(i); try { ...// some error at i } catch(Exception ex) { logger.error("Invalid data found at "+i); break; } processedList.add(myDO); } } 值来驱动代码后面要执行的操作数量(尚未编写)。

代码末尾的类Gtk3+是我将根据在Gtk.SpinButton中输入的数字执行命令的地方。 现在,我已经留下了一个简单的打印命令,以便可以告诉我代码何时可以正常工作。

很抱歉,如果我共享太多代码,我不知道在不共享所有代码的情况下如何正确显示我的问题。

initiate()

我想要的结果是将要输入到gtk.spinbutton中的数字也打印在终端上。相反,我得到了:

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import threading

class MainWindow(Gtk.Window):

        def __init__(self):
                Gtk.Window.__init__(self, title="My App")
                self.set_default_size(100, 100)
                self.set_border_width(10)

                #box
                self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=100)
                self.add(self.box)

                #label
                label = Gtk.Label()
                label.set_text("Welcome to My App!")
                self.box.pack_start(label, True, True, 0)

                #Number of files too rename
                self.renamenum = Gtk.SpinButton()
                self.box.pack_start(self.renamenum, True, True, 0)
                numfiles = self.renamenum.get_value();

                #Button1
                self.button1 = Gtk.Button(label="Start")
                self.button1.connect("clicked", self.button1_clicked)
                self.box.pack_end(self.button1, True, True, 0)

        def button1_clicked(self, widget):
                dialog = PopUp(self)
                response = dialog.run()
                if response == Gtk.ResponseType.CANCEL:
                        dialog.destroy()
                        Gtk.main_quit()
                else:
                        pass

class PopUp(Gtk.Dialog):

        def __init__(self, parent):
                Gtk.Dialog.__init__(self, "Renaming Files", parent, 
Gtk.DialogFlags.MODAL, (
                        "Cancel", Gtk.ResponseType.CANCEL
                ))
                self.set_default_size(500, 500)
                self.set_border_width(50)

                area = self.get_content_area()
                area.add(Gtk.Label("Running..."))
                self.show_all()

                initiate()

class initiate(MainWindow):

        def __init__(self):
                self.var1 = MainWindow()
                num = int(self.var1.numfiles)
                print (numfiles)

window = MainWindow()
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()

0 个答案:

没有答案