2016-12-17 6 views
0

私はゲームを作成しています。私はいくつかのグラフィックスを追加したいと思います。私は線を作ろうとしましたが、半分しか見ることができません。tkinterのpythonで行の半分を表示する

Screenshot showing a line that only goes about halfway across the window

そして、この私のコードです:

import Tkinter as tk 
from PIL import Image, ImageTk 
import time 
import calculate 

class Core(tk.Tk): 

def run(self): 
    self.mainloop() 

def show_frame(self, page_name): 
    '''Show a frame for the given page name''' 
    frame = self.frames[page_name] 
    frame.tkraise() 

def __init__(self, color): 
    tk.Tk.__init__(self) 

    container = tk.Frame(self) 
    self.geometry("600x600") 
    self.configure(background=color) 

    self.resizable(width=False, height=False) 
    container.pack(side="top", fill="both", expand=True) 


    self.iconbitmap('icon.ico') 

    self.frames = {} 
    for F in (Home, Game): 
     page_name = F.__name__ 
     frame = F(parent=container, controller=self) 
     self.frames[page_name] = frame 
     frame.grid(row=0, column=0, sticky="nsew") 


class Home(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 

     self.controller = controller 
     label = tk.Label(self, text="This is page 1") 
     label.pack(side="top", fill="x", pady=10) 


class Game(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     canvas = tk.Canvas(self) 
     canvas.pack(side='top', fill=tk.BOTH, expand=True) 

     canvas.create_line(0, 0, 600, 600) 
     #calculate.drawp(100, canvas, 600, 120, 300, 600, self) 



def main(color): 
    app = Core(color) 
    app.show_frame("Game") 
    app.run() 

main("#e67e22") 

私はこれが起こっている理由が表示されません。私たちを手伝ってくれますか?

+0

あなたは間違った字下げをしています - 質問を編集し、 '{}'ボタンを使って正しい字下げでコードを渡してください。 – furas

+0

Canvasはフルウィンドウを使用しません。 – furas

+0

キャンバスがすべてのウィンドウを占有していない – Stephie

答えて

0

キャンバスはフル・ウィンドウを使用しないため、フル・ラインが表示されません。

使用

container['bg'] = 'red' 

、あなたは

enter image description here

あなたは

canvas.config(width=600, height=600) 

キャンバス

のサイズを変更したり、グリッド内のセルの最小サイズを設定することができます表示されます

container.columnconfigure(0, minsize=600) 
container.rowconfigure(0, minsize=600) 
関連する問題