因爲我問這個問題,我沒有足夠的研究來回答它自己,至少一個相當不錯的答案暫且。我將發佈我用於最終格式的代碼。
from tkinter import *
from tkinter import ttk
#create root window
root = Tk()
root.geometry('640x480+25+75')
root.title('Dragon Slayer')
root.resizable(0,0)
#create Main frame
frame = ttk.Frame(root)
frame.grid(sticky= N+W+E+S)
frame.config(height = 480, width = 640)
frame.config(relief = SUNKEN)
#create Left Controls frame
frame_controls = Canvas(frame)
frame_controls.pack(side = 'left')
frame_controls.config(height = 480, width = 125)
frame_controls.config(relief = SUNKEN)
frame_controls.propagate(False)
frame_controls_image = PhotoImage(file = "C:\\Users\\Garry\\Desktop\\Project\\parchment_left_small.gif")
label = ttk.Label(frame_controls)
label.config(image = frame_controls_image)
label.pack()
label.config(relief = SUNKEN)
#Create Control buttons
create_button = ttk.Button(label, text = "New Player")
create_button.place(x =23, y =15)
monastary_button = ttk.Button(label, state = 'disabled', text = "Monastary")
monastary_button.place(x =23, y =55)
fields_button = ttk.Button(label, state = 'disabled', text = "Fields")
fields_button.place(x =23, y =95)
item_shop_button = ttk.Button(label, state = 'disabled', text = "Item shop")
item_shop_button.place(x =23, y =135)
kill_button = ttk.Button(label, state = 'disabled', text = "Kill Player")
kill_button.place(x =23, y =175)
#Create Game Frames
frame_location_image = PhotoImage(file = "C:\\Users\\Garry\\Desktop\\Project\\parchment_top.gif")
frame_location = Canvas(frame)
frame_location.pack(side = 'top')
frame_location.config(height = 240, width = 515)
frame_location.config(relief = SUNKEN)
frame_location_label = ttk.Label(frame_location)
frame_location_label.config(image = frame_location_image)
frame_location_label.place(x=0,y=0)
frame_location_label.config(compound = 'center')
#create action frames
frame_action_image = PhotoImage(file = "C:\\Users\\Garry\\Desktop\\Project\\parchment_bottom.gif")
frame_action = Canvas(frame)
frame_action.pack(side = 'bottom')
frame_action.config(height = 240, width = 515)
frame_action.config(relief = SUNKEN)
frame_action_label = ttk.Label(frame_action, text = "Action")
frame_action_label.config(image = frame_action_image)
frame_action_label.place(x=0,y=0)
frame_action_label.config(compound = 'center')
#create stats window
stats_window = Toplevel(root)
stats_window.state('withdrawn')
stats_window.title('Stats')
stats_window.geometry('200x480+680+75')
stats_window.resizable(True, True)
frame_stats_background = PhotoImage(file = "C:\\Users\\Garry\\Desktop\\Project\\parchment_stats.gif")
frame_stats_window = Canvas(stats_window)
frame_stats_window.place(x=0, y=0)
frame_stats_window.config(height = 480, width = 200)
frame_stats_window.config(relief = SUNKEN)
stats_file = open('C:\\Users\\Garry\\Desktop\\Project\\stats.txt', 'r')
stats = stats_file.read()
frame_stats_label = ttk.Label(frame_stats_window,text = stats)
frame_stats_label.config(image = frame_stats_background, compound ='center')
frame_stats_label.pack(side = 'left')
frame_stats_label.config(font = "Helvetica 16 bold")
#create monster stats window
monster_stats_window = Toplevel(root)
monster_stats_window.state('withdrawn')
monster_stats_window.title('Monster Stats')
monster_stats_window.geometry('200x480+900+75')
monster_stats_window.resizable(True, True)
monster_frame_stats_window = Canvas(monster_stats_window)
monster_frame_stats_window.place(x=0, y=0)
monster_frame_stats_window.config(height = 480, width = 200)
monster_frame_stats_window.config(relief = SUNKEN)
monster_stats_file = open('C:\\Users\\Garry\\Desktop\\Project\\monsterstats.txt', 'r')
monster_stats = monster_stats_file.read()
monster_frame_stats_label = ttk.Label(monster_frame_stats_window,text = monster_stats)
monster_frame_stats_label.config(image = frame_stats_background, compound ='center')
monster_frame_stats_label.pack(side = 'left')
monster_frame_stats_label.config(font = "Helvetica 16 bold")
#buttons
kill_monster_button = ttk.Button(label, text = "Kill Monster")
fight_button = ttk.Button(frame_action_label, text = "Fight")
run_button = ttk.Button(frame_action_label, text = "Run!")
look_button = ttk.Button(frame_action_label, text = "Look")
leave_fields_button = ttk.Button(frame_action_label, text = "Leave")
leave_item_shop_button = ttk.Button(frame_action_label, text = "Leave")
heal_button = ttk.Button(frame_action_label, text = "Heal")
revive_button = ttk.Button(frame_action_label, text = "Revive")
I hope this helps someone else to find the answers they need. good luck to all
我用帆布,幀的設置幾何形狀,設置窗口的幾何形狀製成的窗戶沒有可觀的,現在我有一個像放置一個文本控件我結束了一個灰色背景的新問題和我有畫布與背景設定圖像,所以我需要知道如何獲得透明背景文本小部件。因爲顯然使用化合物,您必須移動背景圖片或將文本居中...... –