9. GUI Programming Using Tkinter - 42 Questions


9. GUI Programming Using Tkinter

9. GUI Programming Using Tkinter

42 Questions
Created by Y. Daniel Liang - http://www.cs.armstrong.edu/liang/index.html
Free
The tkinter package is a thin object-oriented layer on top of Tcl/Tk. To use tkinter, you don't need to write Tcl code, but you will need to consult the Tk documentation, and occasionally the Tcl documentation. tkinter is a set of wrappers that implement the Tk widgets as Python classes. In addition, the internal module _tkinter provides a threadsafe mechanism which allows Python and Tcl to interact. tkinter's chief virtues are that it is fast, and that it usually comes bundled with Python.
  1. How do you create a window?



    window = newWindow()
    window = Window()
    window = Frame()
    window = Tk()

    View Answer | Discuss in forum
  2. How do you create a frame?




    frame = newWindow()
    frame = Window()
    frame = Frame()
    frame = Tk()

    View Answer | Discuss in forum
  3. How do you create an event loop?



    window.loop()
    window.main()
    window.mainloop()
    window.eventloop()

    View Answer | Discuss in forum
  4. To create a label under parent window, use _______.



    label = Label(text = "Welcome to Python")
    label = Label(window, text = "Welcome to Python")
    label = Label(text = "Welcome to Python", fg = " red")
    label = Label(text = "Welcome to Python", fg = " red", bg = "white")

    View Answer | Discuss in forum
  5. To create a button under parent window with command processButton, use _______.



    Button(text = "OK", fg = "red", command = processButton)
    Button(window, text = "OK", fg = "red")
    Button(window, text = "OK", fg = "red")
    Button(window, text = "OK", command = processButton)

    View Answer | Discuss in forum
  6. Assume v1 = IntVar(), how do you set a new value 5 to v1.



    v1 = 5
    v1.setValue(5)
    v1.set(5)
    v1.get(5)

    View Answer | Discuss in forum
  7. Assume v1 = IntVar(), how do you create a check button under parent frame1 with variable bound to v1?



    Checkbutton(frame1, text = "Bold", command = processCheckbutton)
    Checkbutton(frame1, text = "Bold", variable = v1.get())
    Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton)
    Checkbutton(frame1, text = "Bold", variable = v1.set(), command = processCheckbutton)

    View Answer | Discuss in forum
  8. Assume v1 = IntVar(), how do you create a radio button under parent frame1 with variable bound to v1 and value 1?



    Checkbutton(frame1, text = "Bold", command = processCheckbutton)
    Checkbutton(frame1, text = "Bold", variable = v1.get())
    Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton)
    Radiobutton(frame1, text = "Yellow", bg = "yellow", variable = v1, value = 1, command = processRadiobutton)

    View Answer | Discuss in forum
  9. Assume name = StringVar(), how do you create a text field (entry) under parent frame2 with variable bound to name?



    entryName = Entry(frame2, textvariable = name)
    entryName = Entry(frame2, variable = name, value = "")
    entryName = Entry(frame2, textvariable = name, command = processEntry)
    entryName = Entry(frame2, text = name, command = processEntry)

    View Answer | Discuss in forum
  10. How do you create a GUI component for displaying multiple-lines of text?



    use Label
    Use Button
    Use Text
    Use Message

    View Answer | Discuss in forum
  11. How do you create a text area?



    use Label
    Use Button
    Use Text
    Use Message

    View Answer | Discuss in forum
  12. How do you create a canvas under parent frame1 with background color white and foregroung color green?



    Canvas(frame1, bg = "white", fg = "green")
    Canvas(frame1, bg = "white", fg = "green", command = processEvent)
    Canvas(frame1, bg = "white", command = processEvent)
    Canvas(frame1, fg = "green", command = processEvent)

    View Answer | Discuss in forum
  13. How do you draw a rectangle centered at 100, 100 with width 100 and height 100 on canvas?



    canvas.create_rect(100, 100, 100, 100)
    canvas.create_rectangle(100, 100, 100, 100)
    canvas.create_rect(100 - 50, 100 - 50, 100 + 50, 100 + 50)
    canvas.create_rectangle(100 - 50, 100 - 50, 100 + 50, 100 + 50)

    View Answer | Discuss in forum
  14. How do you draw a circle rectangle centered at 100, 100 with radius 100 on canvas?



    canvas.create_oval(100, 100, 100, 100)
    canvas.create_oval(100 - 100, 100 - 100, 100 + 100, 100 + 100)
    canvas.create_oval(100 - 50, 100 - 50, 100 + 50, 100 + 50)
    canvas.create_circle(100 - 100, 100 - 100, 100 + 100, 100 + 100)

    View Answer | Discuss in forum
  15. How do you draw an arc centered at 100, 100 with radius 20, starting angle 15, ending angle 50, filled with red color on canvas?



    canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 50)
    canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 35)
    canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, filled = "red", start = 15, extent = 50)
    canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, end = 50)

    View Answer | Discuss in forum
  16. How do you draw a red line from 100, 100 to 400, 500?



    canvas.create_line(100, 100, 100, 500, fill = "red")
    canvas.create_line(100, 100, 400, 100, fill = "Red")
    canvas.create_line(100, 100, 400, 500, filled = "red")
    canvas.create_line(100, 100, 400, 500, fill = "red")

    View Answer | Discuss in forum
  17. How do you draw a polygon consisting of points (30, 40), (50, 50), (10, 100) filled with red color?



    canvas.create_poly(30, 40, 50, 50, 10, 100, fill = "red")
    canvas.create_polygon(30, 40, 50, 50, 10, 100, filled = "red")
    canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red")
    canvas.create_polygon((30, 40), (50, 50), (10, 100), fill = "red")

    View Answer | Discuss in forum
  18. How do you display a text "Good morning" centered at 30, 40 with color red?



    canvas.create_text(30, 40, text = "Good morning", fill = "red")
    canvas.create_polygon(30, 40, 50, 50, 10, 100, filled = "red")
    canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red")
    canvas.create_polygon((30, 40), (50, 50), (10, 100), fill = "red")

    View Answer | Discuss in forum
  19. _______ are geometry managers in Tkinter.



    pack
    grid
    place
    all of above

    View Answer | Discuss in forum
  20. To place a button in a specified row and column in its parent container, use ________.



    pack manager
    grid manager
    place manager
    flow manager

    View Answer | Discuss in forum
  21. Which option do you use to put the components in a container using the pack manager in the same row?



    component.pack(LEFT)
    component.pack(side = LEFT)
    component.pack(side = "LEFT")
    component.pack("LEFT")

    View Answer | Discuss in forum
  22. The side option of the pack manager may be _____________.



    LEFT
    RIGHT
    BOTTOM
    All of above

    View Answer | Discuss in forum
  23. Using a grid manager, you can use the option _________ to place a component in multiple rows and columns.



    row
    column
    rowspan & columnspan
    none of these

    View Answer | Discuss in forum
  24. To create an image, use ______________________.



    image = PhotoImage(imagefilename)
    image = Image(file = imagefilename)
    image = PhotoImage(file = imagefilename)
    image = PhotoImage(imagefilename)

    View Answer | Discuss in forum
  25. You can create an image from a ____________ file.



    .png
    .gif
    .bmp
    .jpg

    View Answer | Discuss in forum
  26. You can display an image in ______________.



    a label
    a button
    a check button
    All of above

    View Answer | Discuss in forum
  27. To create a menu in a window, use __________



    menubar = Menu(window)
    menubar = MenBar(window)
    menubar = Menu()
    menubar = MenBar()

    View Answer | Discuss in forum
  28. To add a menu in a menubar, use __________



    menu1 = Menu(menubar)
    menu1 = menu(menubar)
    menu1 = Menu(winodw)
    menu1 = Menu()

    View Answer | Discuss in forum
  29. To add a menubar, use __________



    window.configure(menu = menubar)
    window.config(menubar)
    window.config(menu = menubar)
    window.configure(menubar)

    View Answer | Discuss in forum
  30. To display a popup menu, use __________



    menu.display()
    menu.post()
    menu.display(300, 300)
    menu.post(300, 300)

    View Answer | Discuss in forum
  31. To bind a canvas with a left mouse click event p, use __________



    canvas.left(p)
    canvas.bind("<Button-1>", p)
    canvas.bind("Button-1", p)
    canvas.bind(<Button-1>, p)

    View Answer | Discuss in forum
  32. To bind a canvas with a right mouse click event p, use __________



    canvas.left(p)
    canvas.bind("<Button-1>", p)
    canvas.bind("Button-1", p)
    canvas.bind("<Button-3>", p)

    View Answer | Discuss in forum
  33. To bind a canvas with a mouse entered event p, use __________



    canvas.entered(p)
    canvas.bind("<Enter>", p)
    canvas.bind("<Entered>", p)
    canvas.bind(<Enter>, p)

    View Answer | Discuss in forum
  34. The event _____________ is fired when the mouse is moved while the middle mouse is being held down.



    <B1-Motion>
    <B2-Motion>
    <B3-Motion>
    <Button-1>

    View Answer | Discuss in forum
  35. The event _____________ is fired when the right mouse button is released.



    <ButtonReleased-1>
    <ButtonReleased-2>
    <ButtonReleased-3>
    <ButtonPressed-1>

    View Answer | Discuss in forum
  36. The event _____________ is fired when the right mouse button is double-clicked.



    <Double-Button-1>
    <Double-Button-2>
    <Double-Button-3>
    <Triple-Button-1>

    View Answer | Discuss in forum
  37. To bind a canvas with a key event p, use __________



    canvas.entered(p)
    canvas.bind("<Enter>", p)
    canvas.bind("<Key>", p)
    canvas.bind(<Enter>, p)

    View Answer | Discuss in forum
  38. The mouse event object has the property ____________.



    x
    y
    widget
    All of above

    View Answer | Discuss in forum
  39. To display a message dialog named "Programming is fun", use __________



    tkinter.messagebox.showinfo("showinfo", "Programming is fun")
    tkinter.messagebox.showwarning("showwarning", "Programming is fun")
    tkinter.messagebox.showerror("showerror", "Programming is fun")
    tkinter.messagebox.askyesno("ashyesno", "Programming is fun")

    View Answer | Discuss in forum
  40. To display a warning dialog named "Variable is assigned, but not used", use __________



    tkinter.messagebox.showinfo("showinfo", "Variable is assigned, but not used")
    tkinter.messagebox.showwarning("showwarning", "Variable is assigned, but not used")
    tkinter.messagebox.showerror("showerror", "PVariable is assigned, but not used")
    tkinter.messagebox.askyesno("ashyesno", "Variable is assigned, but not used")

    View Answer | Discuss in forum
  41. To display an error dialog named "Variable is not assigned", use __________



    tkinter.messagebox.showinfo("showinfo", "Variable is not assigned")
    tkinter.messagebox.showwarning("showwarning", "Variable is not assigned")
    tkinter.messagebox.showerror("showerror", "Variable is not assigned")
    tkinter.messagebox.askyesno("ashyesno", "Variable is not assigned")

    View Answer | Discuss in forum
  42. To display an input dialog named "Is this an integer?", use __________



    tkinter.messagebox.showinfo("showinfo", "Is this an integer?")
    tkinter.messagebox.showwarning("showwarning", "Is this an integer?")
    tkinter.messagebox.showerror("showerror", "Is this an integer?")
    tkinter.messagebox.askyesno("ashyesno", "Is this an integer?")

    View Answer | Discuss in forum