2016-08-22 1 views
1

私は再びPythonを書く上でいくつかの問題に遭遇し、私の助けを求めています。リストボックスウィジェットを構築していますが、スクロールバーを設定することはできません。私は右の位置にスクロールバーを置くことができますが、上下は動きませんし、 "Object()はパラメータを取らない"というエラーをポップアップします。誰もそれを修正する方法をアドバイスできますか?参考のために以下のコードを添付しました。tkinter.Listboxスクロールバーyview

import tkinter 
from tkinter import * 

def test(): 
    root = tkinter.Tk() 
    lst = ['1', '2', ' 3', '4', '5', ' 6', '7', '8', ' 9', '10'] 
    a = MovListbox(root, lst) 
    a.grid(row=0, column=0, columnspan=2, sticky=tkinter.N) 
    root.mainloop() 

class MovListbox(tkinter.Listbox): 

    def __init__(self, master=None, inputlist=None): 
     super(MovListbox, self).__init__(master=master) 

     # Populate the news category onto the listbox 
     for item in inputlist: 
      self.insert(tkinter.END, item) 

     #set scrollbar 
     s = tkinter.Scrollbar(master, orient=VERTICAL, command=tkinter.YView) 
     self.configure(yscrollcommand=s.set) 
     s.grid(row=0, column=2, sticky=tkinter.N+tkinter.S) 

if __name__ == '__main__': 
    test() 
+2

に基づいてコードを修正しました。 –

+0

クイックコメントありがとうございます。私はそれを試みましたが、 "MoveListboxオブジェクトには属性YViewがありません"というエラーが表示されます –

+1

'YView'!=' yview' ... –

答えて

1

あなたがimportを使用しimport tkinterfrom tkinter import *

  • の両方を必要としないすべての最初は、あなたがfromを使用すると、あなたのように関数を呼び出すことができることを意味し
  • のTkinterから機能 を呼び出すためにtkinter.'function'を必要とする意味します のプログラムで、開始時にtkinter.がない場合
  • Tkinterの

からすべての機能を取るの手段はまた、私は、私はそれが `コマンド= self.yview`されるべきだと思うRawigの答え

import tkinter 

def test(): 
    root = tkinter.Tk() 
    lst = ['1', '2', ' 3', '4', '5', ' 6', '7', '8', ' 9', '10'] 
    a = MovListbox(root, lst) 
    a.grid(row=0, column=0, columnspan=2, sticky=tkinter.N) 
    root.mainloop() 

class MovListbox(tkinter.Listbox): 

    def __init__(self, master=None, inputlist=None): 
     super(MovListbox, self).__init__(master=master) 

     # Populate the news category onto the listbox 
     for item in inputlist: 
      self.insert(tkinter.END, item) 

     #set scrollbar 
     s = tkinter.Scrollbar(master, orient=VERTICAL, command=self.yview) 
     self.configure(yscrollcommand=s.set) 
     s.grid(row=0, column=2, sticky=tkinter.N+tkinter.S) 

if __name__ == '__main__': 
    test()