class Lnput_lnitialization(): def __init__(self, top, Number_of_rows): self.top = top int(data_demo.window_width // 3.9875) int(data_demo.window_height // 1.138) self.frame = tk.Frame(self.top, bg='Black', highlightthickness=2, highlightbackground='Black') self.frame.place(relx=0.739, rely=0.083, width=int(data_demo.window_width // 3.87), height=int(data_demo.window_height // 1.15)) self.canvas = tk.Canvas(self.frame) self.canvas.place(relx=0, rely=0, width=int(data_demo.window_width // 3.9875), height=int(data_demo.window_height // 1.15)) scrollbar = tk.Scrollbar(self.frame, command=self.canvas.yview) scrollbar.pack(side="right", fill="y") self.canvas.configure(yscrollcommand=scrollbar.set) self.button_frame = tk.Frame(self.canvas, bg='Yellow') self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw") self.Content(Number_of_rows) # 在步骤栏创建填写框 def Content(self, Number_of_rows): x = 0.01 y = 0.01 for a in range(Number_of_rows): var = tk.IntVar() checkbutton1 = Checkbutton(self.button_frame, variable=var, text="{}".format(data_demo.Serial_Number), compound='right') checkbutton1.grid(row=data_demo.Serial_Number, column=1, padx=3, pady=5) data_demo.checkbutton1_boxs.append(checkbutton1) data_demo.checkbutton_bool.append(var) combobox1 = ttk.Combobox(self.button_frame, values=["遥控", "语音", "随机"], width=4) combobox1.grid(row=data_demo.Serial_Number, column=2, padx=6, pady=5) data_demo.comboxox_boxs.append(combobox1)怎么让他自适应大小
时间: 2024-03-18 12:42:41 浏览: 14
可以考虑使用`pack_propagate(False)`方法来禁止自动调整大小,然后使用`pack(fill=BOTH, expand=True)`来使其自适应大小。具体修改方法如下:
1. 将`self.button_frame`的`pack()`方法更改为`pack_propagate(False)`,以禁止自动调整大小。
2. 在`self.canvas.create_window()`方法中添加`pack(fill=BOTH, expand=True)`,以使其自适应大小。
修改后的代码如下:
```
self.button_frame = tk.Frame(self.canvas, bg='Yellow')
self.button_frame.pack_propagate(False) # 禁止自动调整大小
self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw")
self.button_frame.pack(fill=BOTH, expand=True) # 使其自适应大小
```
相关问题
class Lnput_lnitialization(): def __init__(self, top, Number_of_rows): self.top = top int(data_demo.window_width // 3.9875) int(data_demo.window_height // 1.138) self.frame = tk.Frame(self.top, bg='Black', highlightthickness=2, highlightbackground='Black') self.frame.place(relx=0.739, rely=0.083, width=int(data_demo.window_width // 3.87), height=int(data_demo.window_height // 1.15)) self.canvas = tk.Canvas(self.frame) self.canvas.place(relx=0, rely=0, width=int(data_demo.window_width // 3.9875), height=int(data_demo.window_height // 1.15)) scrollbar = tk.Scrollbar(self.frame, command=self.canvas.yview) scrollbar.pack(side="right", fill="y") self.canvas.configure(yscrollcommand=scrollbar.set) self.button_frame = tk.Frame(self.canvas, bg='Yellow') self.button_frame.pack_propagate(False) # 禁止自动调整大小 self.button_frame.pack(fill=BOTH, expand=True) # 使其自适应大小 self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw") self.button_frame.columnconfigure(0, weight=1) self.button_frame.columnconfigure(1, weight=1) self.button_frame.columnconfigure(2, weight=1) self.button_frame.columnconfigure(3, weight=1) self.button_frame.columnconfigure(4, weight=1) self.button_frame.columnconfigure(5, weight=1) self.Content(Number_of_rows)为什么用不了滚轮了
这段代码中使用了tkinter的Canvas组件来创建一个可滚动的窗口,但是在代码中并没有对Canvas绑定滚轮事件的处理程序。因此,当鼠标滚轮事件发生时,Canvas并没有响应。解决方法是在代码中使用canvas.bind()方法绑定滚轮事件,并在绑定的处理程序中调用Canvas的yview()方法来实现滚动。具体实现可以参考下面的示例代码:
```python
class Lnput_lnitialization():
def __init__(self, top, Number_of_rows):
self.top = top
int(data_demo.window_width // 3.9875)
int(data_demo.window_height // 1.138)
self.frame = tk.Frame(self.top, bg='Black', highlightthickness=2, highlightbackground='Black')
self.frame.place(relx=0.739, rely=0.083, width=int(data_demo.window_width // 3.87), height=int(data_demo.window_height // 1.15))
self.canvas = tk.Canvas(self.frame)
self.canvas.place(relx=0, rely=0, width=int(data_demo.window_width // 3.9875), height=int(data_demo.window_height // 1.15))
scrollbar = tk.Scrollbar(self.frame, command=self.canvas.yview)
scrollbar.pack(side="right", fill="y")
self.canvas.configure(yscrollcommand=scrollbar.set)
self.button_frame = tk.Frame(self.canvas, bg='Yellow')
self.button_frame.pack_propagate(False) # 禁止自动调整大小
self.button_frame.pack(fill=BOTH, expand=True) # 使其自适应大小
self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw")
self.button_frame.columnconfigure(0, weight=1)
self.button_frame.columnconfigure(1, weight=1)
self.button_frame.columnconfigure(2, weight=1)
self.button_frame.columnconfigure(3, weight=1)
self.button_frame.columnconfigure(4, weight=1)
self.button_frame.columnconfigure(5, weight=1)
self.Content(Number_of_rows)
self.canvas.bind("<MouseWheel>", self.on_mousewheel)
def on_mousewheel(self, event):
self.canvas.yview_scroll(-1 * int(event.delta / 120), "units")
```
写一段c语言代码,首先务必注意所有函数的声明必须在main之前,否则会出现错误,另外不要使用stl。最后,代码的规范性,包括变量命名、排版、注释等也纳入考量范围。以下是这段代码的要求:Description: 假设两个按元素值非递减有序排列的线性表A和B,均以单链表作为存储结构,试编写程序,将A表和B表归并成一个按元素值非递增有序排列的线性表C,并要求利用原表(即A表和B表的)结点空间存放表C。 lnput: 第一行输入两个正整数m,n(m,n<=100),用空格分开,分别表示线性表A和B中元素个数,其后两行分别输入单链表A和B. Output: 输出单链表C。 Sample lnput: 5 5 1 3 7 12 16 2 6 7 13 20 Sample Output: 20 16 13 12 7 7 6 3 2 1
#include<stdio.h>
#include<stdlib.h>
//定义链表节点结构体
typedef struct Node{
int data;
struct Node* next;
}Node;
//函数声明
Node* merge(Node* headA, Node* headB);
void printList(Node* head);
int main(){
//输入线性表A和B的元素个数
int m, n;
scanf("%d%d", &m, &n);
//创建链表A和B
Node* headA = NULL;
Node* headB = NULL;
Node* pA = NULL;
Node* pB = NULL;
for(int i=0; i<m; i++){
int data;
scanf("%d", &data);
Node* node = (Node*)malloc(sizeof(Node));
node->data = data;
node->next = NULL;
if(headA == NULL){
headA = node;
pA = node;
}
else{
pA->next = node;
pA = node;
}
}
for(int i=0; i<n; i++){
int data;
scanf("%d", &data);
Node* node = (Node*)malloc(sizeof(Node));
node->data = data;
node->next = NULL;
if(headB == NULL){
headB = node;
pB = node;
}
else{
pB->next = node;
pB = node;
}
}
//合并链表A和B
Node* headC = merge(headA, headB);
//输出链表C
printList(headC);
return 0;
}
//合并链表函数
Node* merge(Node* headA, Node* headB){
if(headA == NULL){
return headB;
}
if(headB == NULL){
return headA;
}
//定义链表C的头节点
Node* headC = NULL;
if(headA->data >= headB->data){
headC = headA;
headA = headA->next;
}
else{
headC = headB;
headB = headB->next;
}
//指向链表C的当前节点
Node* pC = headC;
while(headA && headB){
if(headA->data >= headB->data){
pC->next = headA;
headA = headA->next;
}
else{
pC->next = headB;
headB = headB->next;
}
pC = pC->next;
}
if(headA){
pC->next = headA;
}
else{
pC->next = headB;
}
//反转链表C
Node* pre = NULL;
Node* cur = headC;
Node* next = NULL;
while(cur){
next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
headC = pre;
return headC;
}
//输出链表函数
void printList(Node* head){
while(head){
printf("%d ", head->data);
head = head->next;
}
}